mirror of
https://github.com/vacp2p/staking-demo-app.git
synced 2026-01-08 20:37:57 -05:00
clean up
This commit is contained in:
@@ -77,7 +77,7 @@
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="flex h-8 w-8 items-center justify-center">
|
||||
{#if lockHash}
|
||||
<button class="cursor-pointer" on:click={() => openTxOnEtherscan(lockHash)}>
|
||||
<button class="cursor-pointer" on:click={() => openTxOnEtherscan(lockHash)} aria-label="View transaction in progress">
|
||||
<svg
|
||||
class="h-5 w-5 animate-spin text-blue-600"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
export let isCompleted = false;
|
||||
export let amount: string | undefined;
|
||||
export let isAllowanceSet = false;
|
||||
export let isResettingAllowance = false;
|
||||
export const isResettingAllowance = false;
|
||||
|
||||
function shortenAddress(address: string | undefined): string {
|
||||
if (!address) return '';
|
||||
@@ -98,6 +98,7 @@
|
||||
<button
|
||||
class="animate-spin"
|
||||
on:click={() => openTxOnEtherscan(approvalHash)}
|
||||
aria-label="View approval transaction in progress"
|
||||
>
|
||||
<svg class="h-5 w-5 text-blue-600" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||
@@ -129,6 +130,7 @@
|
||||
<button
|
||||
class="animate-spin"
|
||||
on:click={() => openTxOnEtherscan(stakingHash)}
|
||||
aria-label="View staking transaction in progress"
|
||||
>
|
||||
<svg class="h-5 w-5 text-blue-600" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
} from '$lib/viem';
|
||||
import { formatUnits, parseUnits, type Hash } from 'viem';
|
||||
import { openExplorer } from '$lib/utils';
|
||||
import { vaultAbi } from '$lib/contracts';
|
||||
|
||||
export let isOpen = false;
|
||||
export let onClose: () => void;
|
||||
@@ -89,15 +90,7 @@
|
||||
chain: publicClient.chain,
|
||||
account: $walletAddress,
|
||||
address: vaultAddress,
|
||||
abi: [
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }],
|
||||
name: 'unstake',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
}
|
||||
],
|
||||
abi: vaultAbi,
|
||||
functionName: 'unstake',
|
||||
args: [amountToUnstake]
|
||||
});
|
||||
@@ -185,7 +178,7 @@
|
||||
<div class="flex items-center gap-3">
|
||||
{#if isUnstaking}
|
||||
<div class="flex h-8 w-8 items-center justify-center">
|
||||
<button class="animate-spin" on:click={() => openTxOnEtherscan(unstakeHash)}>
|
||||
<button class="animate-spin" on:click={() => openTxOnEtherscan(unstakeHash)} aria-label="View unstaking transaction in progress">
|
||||
<svg
|
||||
class="h-5 w-5 text-blue-600"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
@@ -258,10 +251,11 @@
|
||||
<div class="mt-6 space-y-6">
|
||||
<!-- Amount Slider -->
|
||||
<div>
|
||||
<label class="mb-1 block text-sm font-medium text-gray-700">
|
||||
<label for="unstake-amount" class="mb-1 block text-sm font-medium text-gray-700">
|
||||
Amount to Unstake
|
||||
</label>
|
||||
<input
|
||||
id="unstake-amount"
|
||||
type="range"
|
||||
min="1"
|
||||
max={maxAmount}
|
||||
@@ -279,7 +273,9 @@
|
||||
|
||||
<!-- Amount Input -->
|
||||
<div class="relative">
|
||||
<label for="unstake-amount-input" class="sr-only">Amount to unstake</label>
|
||||
<input
|
||||
id="unstake-amount-input"
|
||||
type="number"
|
||||
value={amount}
|
||||
on:input={handleAmountInput}
|
||||
|
||||
6
src/lib/contracts/index.ts
Normal file
6
src/lib/contracts/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export { vaultAbi } from './vaultAbi';
|
||||
export { tokenAbi } from './tokenAbi';
|
||||
export { stakingManagerAbi } from './stakingManagerAbi';
|
||||
export { vaultFactoryAbi } from './vaultFactoryAbi';
|
||||
|
||||
// Add any other ABIs as needed
|
||||
44
src/lib/contracts/stakingManagerAbi.ts
Normal file
44
src/lib/contracts/stakingManagerAbi.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
export const stakingManagerAbi = [
|
||||
{
|
||||
inputs: [{ internalType: 'address', name: 'user', type: 'address' }],
|
||||
name: 'getUserVaults',
|
||||
outputs: [{ internalType: 'address[]', name: '', type: 'address[]' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'totalStaked',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'address', name: 'vault', type: 'address' }],
|
||||
name: 'mpBalanceOf',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'address', name: 'accountAddress', type: 'address' }],
|
||||
name: 'getAccount',
|
||||
outputs: [
|
||||
{
|
||||
components: [
|
||||
{ internalType: 'uint256', name: 'stakedBalance', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'accountRewardIndex', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'mpAccrued', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'maxMP', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'lastMPUpdateTime', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'lockUntil', type: 'uint256' }
|
||||
],
|
||||
internalType: 'struct StakingManager.Account',
|
||||
name: '',
|
||||
type: 'tuple'
|
||||
}
|
||||
],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
}
|
||||
] as const;
|
||||
62
src/lib/contracts/tokenAbi.ts
Normal file
62
src/lib/contracts/tokenAbi.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
export const tokenAbi = [
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_owner', type: 'address' }
|
||||
],
|
||||
name: 'balanceOf',
|
||||
outputs: [{ internalType: 'uint256', name: 'balance', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_spender', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_amount', type: 'uint256' }
|
||||
],
|
||||
name: 'approve',
|
||||
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_owner', type: 'address' },
|
||||
{ internalType: 'address', name: '_spender', type: 'address' }
|
||||
],
|
||||
name: 'allowance',
|
||||
outputs: [{ internalType: 'uint256', name: 'remaining', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'decimals',
|
||||
outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'name',
|
||||
outputs: [{ internalType: 'string', name: '', type: 'string' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'symbol',
|
||||
outputs: [{ internalType: 'string', name: '', type: 'string' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_to', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_amount', type: 'uint256' }
|
||||
],
|
||||
name: 'transfer',
|
||||
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
}
|
||||
] as const;
|
||||
40
src/lib/contracts/vaultAbi.ts
Normal file
40
src/lib/contracts/vaultAbi.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
export const vaultAbi = [
|
||||
{
|
||||
inputs: [],
|
||||
name: 'register',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'amountStaked',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'uint256', name: '_amount', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: '_seconds', type: 'uint256' }
|
||||
],
|
||||
name: 'stake',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '_seconds', type: 'uint256' }],
|
||||
name: 'lock',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }],
|
||||
name: 'unstake',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
}
|
||||
] as const;
|
||||
9
src/lib/contracts/vaultFactoryAbi.ts
Normal file
9
src/lib/contracts/vaultFactoryAbi.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export const vaultFactoryAbi = [
|
||||
{
|
||||
inputs: [],
|
||||
name: 'createVault',
|
||||
outputs: [{ internalType: 'contract StakeVault', name: '', type: 'address' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
}
|
||||
] as const;
|
||||
436
src/lib/viem.ts
436
src/lib/viem.ts
@@ -11,6 +11,7 @@ import {
|
||||
} from 'viem';
|
||||
import { sepolia } from 'viem/chains';
|
||||
import { writable, derived, get } from 'svelte/store';
|
||||
import { tokenAbi, vaultAbi, stakingManagerAbi, vaultFactoryAbi } from './contracts';
|
||||
|
||||
const rpcUrl = import.meta.env.VITE_RPC_URL;
|
||||
|
||||
@@ -62,320 +63,6 @@ export function switchChain(chain: Chain) {
|
||||
// This is a simplified approach - in a real app, you'd want to handle this more robustly
|
||||
}
|
||||
|
||||
// Complete contract ABI
|
||||
const CONTRACT_ABI = [
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'string', name: '_tokenName', type: 'string' },
|
||||
{ internalType: 'uint8', name: '_decimalUnits', type: 'uint8' },
|
||||
{ internalType: 'string', name: '_tokenSymbol', type: 'string' },
|
||||
{ internalType: 'bool', name: '_transferable', type: 'bool' }
|
||||
],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'constructor'
|
||||
},
|
||||
{ inputs: [], name: 'AllowanceAlreadySet', type: 'error' },
|
||||
{ inputs: [], name: 'ControllerNotSet', type: 'error' },
|
||||
{ inputs: [], name: 'ControllerRejected', type: 'error' },
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: 'deadline', type: 'uint256' }],
|
||||
name: 'ERC2612ExpiredSignature',
|
||||
type: 'error'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: 'signer', type: 'address' },
|
||||
{ internalType: 'address', name: 'owner', type: 'address' }
|
||||
],
|
||||
name: 'ERC2612InvalidSigner',
|
||||
type: 'error'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: 'account', type: 'address' },
|
||||
{ internalType: 'uint256', name: 'currentNonce', type: 'uint256' }
|
||||
],
|
||||
name: 'InvalidAccountNonce',
|
||||
type: 'error'
|
||||
},
|
||||
{ inputs: [], name: 'InvalidDestination', type: 'error' },
|
||||
{ inputs: [], name: 'InvalidShortString', type: 'error' },
|
||||
{ inputs: [], name: 'NotAuthorized', type: 'error' },
|
||||
{ inputs: [], name: 'NotEnoughAllowance', type: 'error' },
|
||||
{ inputs: [], name: 'NotEnoughBalance', type: 'error' },
|
||||
{ inputs: [], name: 'Overflow', type: 'error' },
|
||||
{ inputs: [], name: 'ParentSnapshotNotReached', type: 'error' },
|
||||
{
|
||||
inputs: [{ internalType: 'string', name: 'str', type: 'string' }],
|
||||
name: 'StringTooLong',
|
||||
type: 'error'
|
||||
},
|
||||
{ inputs: [], name: 'TransfersDisabled', type: 'error' },
|
||||
{
|
||||
anonymous: false,
|
||||
inputs: [
|
||||
{ indexed: true, internalType: 'address', name: 'owner', type: 'address' },
|
||||
{ indexed: true, internalType: 'address', name: 'spender', type: 'address' },
|
||||
{ indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }
|
||||
],
|
||||
name: 'Approval',
|
||||
type: 'event'
|
||||
},
|
||||
{
|
||||
anonymous: false,
|
||||
inputs: [
|
||||
{ indexed: true, internalType: 'address', name: '_token', type: 'address' },
|
||||
{ indexed: true, internalType: 'address', name: '_controller', type: 'address' },
|
||||
{ indexed: false, internalType: 'uint256', name: '_amount', type: 'uint256' }
|
||||
],
|
||||
name: 'ClaimedTokens',
|
||||
type: 'event'
|
||||
},
|
||||
{ anonymous: false, inputs: [], name: 'EIP712DomainChanged', type: 'event' },
|
||||
{
|
||||
anonymous: false,
|
||||
inputs: [
|
||||
{ indexed: true, internalType: 'address', name: 'from', type: 'address' },
|
||||
{ indexed: true, internalType: 'address', name: 'to', type: 'address' },
|
||||
{ indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }
|
||||
],
|
||||
name: 'Transfer',
|
||||
type: 'event'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'DOMAIN_SEPARATOR',
|
||||
outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'TOKEN_VERSION',
|
||||
outputs: [{ internalType: 'string', name: '', type: 'string' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_owner', type: 'address' },
|
||||
{ internalType: 'address', name: '_spender', type: 'address' }
|
||||
],
|
||||
name: 'allowance',
|
||||
outputs: [{ internalType: 'uint256', name: 'remaining', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_spender', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_amount', type: 'uint256' }
|
||||
],
|
||||
name: 'approve',
|
||||
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_spender', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_amount', type: 'uint256' },
|
||||
{ internalType: 'bytes', name: '_extraData', type: 'bytes' }
|
||||
],
|
||||
name: 'approveAndCall',
|
||||
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'address', name: '_owner', type: 'address' }],
|
||||
name: 'balanceOf',
|
||||
outputs: [{ internalType: 'uint256', name: 'balance', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_owner', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_blockNumber', type: 'uint256' }
|
||||
],
|
||||
name: 'balanceOfAt',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'address payable', name: '_newController', type: 'address' }],
|
||||
name: 'changeController',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'contract IERC20', name: '_token', type: 'address' }],
|
||||
name: 'claimTokens',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'controller',
|
||||
outputs: [{ internalType: 'address payable', name: '', type: 'address' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'creationBlock',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'decimals',
|
||||
outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_owner', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_amount', type: 'uint256' }
|
||||
],
|
||||
name: 'destroyTokens',
|
||||
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'eip712Domain',
|
||||
outputs: [
|
||||
{ internalType: 'bytes1', name: 'fields', type: 'bytes1' },
|
||||
{ internalType: 'string', name: 'name', type: 'string' },
|
||||
{ internalType: 'string', name: 'version', type: 'string' },
|
||||
{ internalType: 'uint256', name: 'chainId', type: 'uint256' },
|
||||
{ internalType: 'address', name: 'verifyingContract', type: 'address' },
|
||||
{ internalType: 'bytes32', name: 'salt', type: 'bytes32' },
|
||||
{ internalType: 'uint256[]', name: 'extensions', type: 'uint256[]' }
|
||||
],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'bool', name: '_transfersEnabled', type: 'bool' }],
|
||||
name: 'enableTransfers',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_owner', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_amount', type: 'uint256' }
|
||||
],
|
||||
name: 'generateTokens',
|
||||
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'name',
|
||||
outputs: [{ internalType: 'string', name: '', type: 'string' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'address', name: 'owner', type: 'address' }],
|
||||
name: 'nonces',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'parentSnapShotBlock',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'parentToken',
|
||||
outputs: [{ internalType: 'contract MiniMeBase', name: '', type: 'address' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: 'owner', type: 'address' },
|
||||
{ internalType: 'address', name: 'spender', type: 'address' },
|
||||
{ internalType: 'uint256', name: 'value', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'deadline', type: 'uint256' },
|
||||
{ internalType: 'uint8', name: 'v', type: 'uint8' },
|
||||
{ internalType: 'bytes32', name: 'r', type: 'bytes32' },
|
||||
{ internalType: 'bytes32', name: 's', type: 'bytes32' }
|
||||
],
|
||||
name: 'permit',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'symbol',
|
||||
outputs: [{ internalType: 'string', name: '', type: 'string' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'totalSupply',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '_blockNumber', type: 'uint256' }],
|
||||
name: 'totalSupplyAt',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_to', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_amount', type: 'uint256' }
|
||||
],
|
||||
name: 'transfer',
|
||||
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_from', type: 'address' },
|
||||
{ internalType: 'address', name: '_to', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_amount', type: 'uint256' }
|
||||
],
|
||||
name: 'transferFrom',
|
||||
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'transfersEnabled',
|
||||
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{ stateMutability: 'payable', type: 'receive' }
|
||||
] as const;
|
||||
|
||||
// Token information
|
||||
export const SNT_TOKEN = {
|
||||
address: '0xE452027cdEF746c7Cd3DB31CB700428b16cD8E51' as Address,
|
||||
@@ -421,105 +108,6 @@ type Account = {
|
||||
lockUntil: bigint;
|
||||
};
|
||||
|
||||
// Update STAKING_MANAGER_ABI
|
||||
const STAKING_MANAGER_ABI = [
|
||||
{
|
||||
inputs: [{ internalType: 'address', name: 'user', type: 'address' }],
|
||||
name: 'getUserVaults',
|
||||
outputs: [{ internalType: 'address[]', name: '', type: 'address[]' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'totalStaked',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'address', name: 'vault', type: 'address' }],
|
||||
name: 'mpBalanceOf',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'address', name: 'accountAddress', type: 'address' }],
|
||||
name: 'getAccount',
|
||||
outputs: [
|
||||
{
|
||||
components: [
|
||||
{ internalType: 'uint256', name: 'stakedBalance', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'accountRewardIndex', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'mpAccrued', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'maxMP', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'lastMPUpdateTime', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'lockUntil', type: 'uint256' }
|
||||
],
|
||||
internalType: 'struct StakingManager.Account',
|
||||
name: '',
|
||||
type: 'tuple'
|
||||
}
|
||||
],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
}
|
||||
] as const;
|
||||
|
||||
// Contract ABIs
|
||||
const VAULT_FACTORY_ABI = [
|
||||
{
|
||||
inputs: [],
|
||||
name: 'createVault',
|
||||
outputs: [{ internalType: 'contract StakeVault', name: '', type: 'address' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
}
|
||||
] as const;
|
||||
|
||||
// Vault ABI
|
||||
const VAULT_ABI = [
|
||||
{
|
||||
inputs: [],
|
||||
name: 'register',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'amountStaked',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'uint256', name: '_amount', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: '_seconds', type: 'uint256' }
|
||||
],
|
||||
name: 'stake',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '_seconds', type: 'uint256' }],
|
||||
name: 'lock',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }],
|
||||
name: 'unstake',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
}
|
||||
] as const;
|
||||
|
||||
// Stores for staking data
|
||||
export const userVaults = writable<Address[]>([]);
|
||||
export const vaultAccounts = writable<Record<Address, Account>>({});
|
||||
@@ -564,7 +152,7 @@ async function fetchSntBalance(address: Address) {
|
||||
console.log('Fetching STT balance for address:', address);
|
||||
const balance = await publicClient.readContract({
|
||||
address: SNT_TOKEN.address,
|
||||
abi: CONTRACT_ABI,
|
||||
abi: tokenAbi,
|
||||
functionName: 'balanceOf',
|
||||
args: [address]
|
||||
});
|
||||
@@ -587,7 +175,7 @@ async function fetchVaultAccount(vaultAddress: Address) {
|
||||
try {
|
||||
const account = await publicClient.readContract({
|
||||
address: STAKING_MANAGER.address,
|
||||
abi: STAKING_MANAGER_ABI,
|
||||
abi: stakingManagerAbi,
|
||||
functionName: 'getAccount',
|
||||
args: [vaultAddress]
|
||||
});
|
||||
@@ -625,7 +213,7 @@ async function fetchUserVaults(address: Address) {
|
||||
console.log('Fetching vaults for address:', address);
|
||||
const vaults = await publicClient.readContract({
|
||||
address: STAKING_MANAGER.address,
|
||||
abi: STAKING_MANAGER_ABI,
|
||||
abi: stakingManagerAbi,
|
||||
functionName: 'getUserVaults',
|
||||
args: [address]
|
||||
});
|
||||
@@ -647,7 +235,7 @@ async function fetchTotalStaked() {
|
||||
console.log('Fetching total staked amount');
|
||||
const total = await publicClient.readContract({
|
||||
address: STAKING_MANAGER.address,
|
||||
abi: STAKING_MANAGER_ABI,
|
||||
abi: stakingManagerAbi,
|
||||
functionName: 'totalStaked'
|
||||
});
|
||||
console.log('Received total staked:', total.toString());
|
||||
@@ -754,7 +342,7 @@ export async function deployVault() {
|
||||
chain: sepolia,
|
||||
account: address,
|
||||
address: VAULT_FACTORY.address,
|
||||
abi: VAULT_FACTORY_ABI,
|
||||
abi: vaultFactoryAbi,
|
||||
functionName: 'createVault'
|
||||
});
|
||||
|
||||
@@ -784,7 +372,7 @@ export async function registerVault(vaultAddress: Address) {
|
||||
chain: sepolia,
|
||||
account: address,
|
||||
address: vaultAddress,
|
||||
abi: VAULT_ABI,
|
||||
abi: vaultAbi,
|
||||
functionName: 'register'
|
||||
});
|
||||
|
||||
@@ -826,7 +414,7 @@ export async function stakeTokens(
|
||||
// First check current allowance
|
||||
const currentAllowance = await publicClient.readContract({
|
||||
address: SNT_TOKEN.address,
|
||||
abi: CONTRACT_ABI,
|
||||
abi: tokenAbi,
|
||||
functionName: 'allowance',
|
||||
args: [address, vaultAddress]
|
||||
});
|
||||
@@ -846,7 +434,7 @@ export async function stakeTokens(
|
||||
chain: sepolia,
|
||||
account: address,
|
||||
address: SNT_TOKEN.address,
|
||||
abi: CONTRACT_ABI,
|
||||
abi: tokenAbi,
|
||||
functionName: 'approve',
|
||||
args: [vaultAddress, 0n]
|
||||
});
|
||||
@@ -865,7 +453,7 @@ export async function stakeTokens(
|
||||
chain: sepolia,
|
||||
account: address,
|
||||
address: SNT_TOKEN.address,
|
||||
abi: CONTRACT_ABI,
|
||||
abi: tokenAbi,
|
||||
functionName: 'approve',
|
||||
args: [vaultAddress, amount]
|
||||
});
|
||||
@@ -889,7 +477,7 @@ export async function stakeTokens(
|
||||
chain: sepolia,
|
||||
account: address,
|
||||
address: vaultAddress,
|
||||
abi: VAULT_ABI,
|
||||
abi: vaultAbi,
|
||||
functionName: 'stake',
|
||||
args: [amount, 0n] // 0 seconds lock period
|
||||
});
|
||||
@@ -937,7 +525,7 @@ export async function lockVault(vaultAddress: Address, lockDurationSeconds: numb
|
||||
chain: sepolia,
|
||||
account: address,
|
||||
address: vaultAddress,
|
||||
abi: VAULT_ABI,
|
||||
abi: vaultAbi,
|
||||
functionName: 'lock',
|
||||
args: [BigInt(lockDurationSeconds)]
|
||||
});
|
||||
|
||||
@@ -474,11 +474,12 @@
|
||||
</div>
|
||||
|
||||
<div class="mt-6 space-y-2">
|
||||
<label class="block text-sm font-medium leading-6 text-gray-900">
|
||||
<label for="lock-duration" class="block text-sm font-medium leading-6 text-gray-900">
|
||||
Lock Duration (minimum 90 days)
|
||||
</label>
|
||||
<div>
|
||||
<input
|
||||
id="lock-duration"
|
||||
type="range"
|
||||
min={MIN_LOCK_DAYS}
|
||||
max="1460"
|
||||
@@ -603,7 +604,6 @@
|
||||
isCompleted={isCompleted}
|
||||
amount={amount}
|
||||
isAllowanceSet={isAllowanceSet}
|
||||
isResettingAllowance={isResettingAllowance}
|
||||
/>
|
||||
|
||||
<LockingModal
|
||||
|
||||
Reference in New Issue
Block a user