Skip to content

Commit

Permalink
Use new contract for stake and unstake
Browse files Browse the repository at this point in the history
  • Loading branch information
Gege Li authored and Gege Li committed Aug 1, 2024
1 parent c650347 commit cc599b1
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 5 deletions.
Binary file added public/images/chains/koi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/config/abi/KTONStakingRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,23 @@ export const abi = [
payable: false,
constant: false,
stateMutability: 'nonpayable'
},
{
name: 'lockAndStake',
type: 'function',
inputs: [{ name: 'amount', type: 'uint256', internalType: 'uint256' }],
outputs: [],
payable: false,
constant: false,
stateMutability: 'nonpayable'
},
{
name: 'unlockAndWithdraw',
type: 'function',
inputs: [{ name: 'amount', type: 'uint256', internalType: 'uint256' }],
outputs: [],
payable: false,
constant: false,
stateMutability: 'nonpayable'
}
] as const;
2 changes: 2 additions & 0 deletions src/config/chains/darwinia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ export const darwinia: ChainConfig = {
},
ktonToken: {
address: '0x0000000000000000000000000000000000000402',
//address: '0x6FB1cE2dc2043FEc15d4d8A58cAF06a47A8f025F',
symbol: 'KTON',
decimals: 18,
logoPath: '/images/token/kton.svg'
},
stakingContractAddress: '0x000000000419683a1a03abc21fc9da25fd2b4dd7'
//stakingContractAddress: '0x6FB1cE2dc2043FEc15d4d8A58cAF06a47A8f025F'
} as const satisfies ChainConfig;
1 change: 1 addition & 0 deletions src/config/chains/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './crab';
export * from './darwinia';
export * from './koi';
40 changes: 40 additions & 0 deletions src/config/chains/koi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ChainConfig, ChainId } from "@/types/chains";

export const koi: ChainConfig = {
id: ChainId.KOI,
name: 'Koi',
nativeCurrency: { name: 'KRING', symbol: 'KRING', decimals: 18 },
rpcUrls: {
default: {
http: ['https://koi-rpc.darwinia.network'],
webSocket: ['wss://koi-rpc.darwinia.network']
},
public: {
http: ['https://koi-rpc.darwinia.network'],
webSocket: ['wss://koi-rpc.darwinia.network']
}
},
blockExplorers: {
default: {
name: 'Koi scan',
url: 'https://koi-scan.darwinia.network/'
}
},
iconUrl: '/images/chains/koi.png',

/**
* Token info
*/
nativeToken: {
symbol: 'KRING',
decimals: 18,
logoPath: '/images/token/ring.svg'
},
ktonToken: {
address: '0x0000000000000000000000000000000000000402',
symbol: 'PKTON',
decimals: 18,
logoPath: '/images/token/pkton.svg'
},
stakingContractAddress: '0x6FB1cE2dc2043FEc15d4d8A58cAF06a47A8f025F'
} as const satisfies ChainConfig;
2 changes: 1 addition & 1 deletion src/hooks/useStake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function useStake({ ownerAddress, onSuccess, onError }: UseStakeProps) {
abi,
address: activeChain?.stakingContractAddress,
account: ownerAddress!,
functionName: 'stake',
functionName: 'lockAndStake',
args: [parseEther(amount)]
})?.catch((data) => {
updateOperationStatus('stake', 0);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useUnStake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function useUnStake({ ownerAddress, onError, onSuccess }: UseUnStakeProps
abi,
address: activeChain?.stakingContractAddress,
account: ownerAddress!,
functionName: 'withdraw',
functionName: 'unlockAndWithdraw',
args: [parseEther(amount)]
})?.catch((data) => {
updateOperationStatus('unstake', 0);
Expand Down
3 changes: 2 additions & 1 deletion src/types/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type { Chain } from '@rainbow-me/rainbowkit';
*/
export enum ChainId {
CRAB = 44,
DARWINIA = 46
DARWINIA = 46,
KOI = 701
}

interface NativeToken {
Expand Down
5 changes: 3 additions & 2 deletions src/utils/chain.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { darwinia, crab } from '@/config/chains';
import { darwinia, crab, koi} from '@/config/chains';
import { ChainConfig, ChainId } from '@/types/chains';

// Map object to return a specific chain configuration
// Using Record<ChainId, ChainConfig> to ensure type safety
const chainConfigMap: Record<ChainId, ChainConfig> = {
[ChainId.DARWINIA]: darwinia,
[ChainId.CRAB]: crab
[ChainId.CRAB]: crab,
[ChainId.KOI]: koi
};

// Helper function to filter testnets in production
Expand Down

0 comments on commit cc599b1

Please sign in to comment.