Skip to content

Commit

Permalink
chore: update add chicken pool
Browse files Browse the repository at this point in the history
- fix play chicken
  • Loading branch information
jac18281828 committed Dec 11, 2024
1 parent 95bffc2 commit bba95ef
Show file tree
Hide file tree
Showing 11 changed files with 2,413 additions and 1,413 deletions.
5 changes: 4 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
},
"customizations": {
"vscode": {
"extensions": ["yzhang.markdown-all-in-one"]
"extensions": [
"yzhang.markdown-all-in-one",
"esbenp.prettier-vscode"
]
}
}
}
Binary file modified bun.lockb
Binary file not shown.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"chicken": "node dist/main.js",
"breeze": "node dist/main.js",
"clean": "rm -rf build",
"lint": "eslint --cache --cache-location ./node_modules/.cache/eslint src/**/*.ts",
"prettier:fix": "prettier --write .",
"prettier:check": "prettier --check .",
"launch": "ts-node src/launch_eth.ts",
"prettier:fix": "prettier --write src/**/*.{ts,json}",
"prettier:check": "prettier --check src/**/*.{ts,json}",
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -29,5 +28,6 @@
"ethers": "^6.13.4",
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"yargs": "^17.2.1"
}
}
32 changes: 32 additions & 0 deletions src/ChickenLauncher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ethers } from 'ethers';

import ChickenLauncherAbi from './abi/ChickenLauncher.json';

const LAUNCHER_CONTRACT_ADDRESS = '0x4db097b90530f111e88325e514c9a0d59392db9e';

export class ChickenLauncher {
rpcUrl: string;
wallet: ethers.Wallet;
provider: ethers.JsonRpcProvider;
contract: ethers.Contract;

constructor(rpcUrl: string, wallet: ethers.Wallet, provider: ethers.JsonRpcProvider) {
this.rpcUrl = rpcUrl;
this.wallet = wallet;
this.provider = provider;
this.contract = new ethers.Contract(LAUNCHER_CONTRACT_ADDRESS, ChickenLauncherAbi, wallet);
}

async launch(
tokenName: string,
tokenSymbol: string,
initialMint: number,
initialOwner: string,
supplyCap: number,
): Promise<void> {
const initialMintWei = ethers.parseUnits(initialMint.toString(), 18);
const supplyCapWei = ethers.parseUnits(supplyCap.toString(), 18);
const tx = await this.contract.launch(tokenName, tokenSymbol, initialMintWei, initialOwner, supplyCapWei);
console.log(`Transaction hash: ${tx.hash}`);
}
}
51 changes: 51 additions & 0 deletions src/ChickenPool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ethers } from 'ethers';

import ChickenPoolAbi from './abi/PlayChicken.json';

const CHICKEN_POOL_ADDRESS = '0x9ee040266605a8b0b65d859cfa6e2b7d5f34c163';

export class ChickenPool {
rpcUrl: string;
wallet: ethers.Wallet;
provider: ethers.JsonRpcProvider;
contract: ethers.Contract;

constructor(rpcUrl: string, wallet: ethers.Wallet, provider: ethers.JsonRpcProvider) {
this.rpcUrl = rpcUrl;
this.wallet = wallet;
this.provider = provider;
this.contract = new ethers.Contract(CHICKEN_POOL_ADDRESS, ChickenPoolAbi, wallet);
}

// function start(address _token, uint256 _buyIn, uint256 _slashingPercent) external whenNotPaused nonReentrant {
async start(token: string, buyIn: number, slashingPercent: number): Promise<void> {
const buyInInWei = ethers.parseEther(buyIn.toString());
const tx = await this.contract.start(token, buyInInWei, slashingPercent);
console.log(`Transaction hash: ${tx.hash}`);
}

async join(poolId: number, deposit: number): Promise<void> {
const depositWei = ethers.parseEther(deposit.toString());
const tx = await this.contract.join(poolId, depositWei);
console.log(`Transaction hash: ${tx.hash}`);
}

async withdraw(poolId: number): Promise<void> {
const tx = await this.contract.withdraw(poolId);
console.log(`Transaction hash: ${tx.hash}`);
}

async claim(poolId: number): Promise<void> {
const tx = await this.contract.claim(poolId);
console.log(`Transaction hash: ${tx.hash}`);
}

async withdrawProtocolFee(poolId: number): Promise<void> {
const tx = await this.contract.withdrawProtocolFee(poolId);
console.log(`Transaction hash: ${tx.hash}`);
}

getAddress(): string {
return CHICKEN_POOL_ADDRESS;
}
}
111 changes: 55 additions & 56 deletions src/RewardPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,69 @@ import { ethers } from 'ethers';

import RewardPoolAbi from './abi/RewardChicken.json';

const REWARD_POOL_ADDRESS = '0x0c41734FD47D62F26B49f096210063df6307d618';
const REWARD_POOL_ADDRESS = '0xf31799A6893EE2508B2b12eab12b9146B074A5f3';

export class RewardPool {
rpcUrl: string;
wallet: ethers.Wallet;
provider: ethers.JsonRpcProvider;
contract: ethers.Contract;
rpcUrl: string;
wallet: ethers.Wallet;
provider: ethers.JsonRpcProvider;
contract: ethers.Contract;

constructor(rpcUrl: string, wallet: ethers.Wallet, provider: ethers.JsonRpcProvider) {
this.rpcUrl = rpcUrl;
this.wallet = wallet;
this.provider = provider;
this.contract = new ethers.Contract(REWARD_POOL_ADDRESS, RewardPoolAbi, wallet);
}
constructor(rpcUrl: string, wallet: ethers.Wallet, provider: ethers.JsonRpcProvider) {
this.rpcUrl = rpcUrl;
this.wallet = wallet;
this.provider = provider;
this.contract = new ethers.Contract(REWARD_POOL_ADDRESS, RewardPoolAbi, wallet);
}

// function start(address _token, uint256 _start, uint256 _end, uint256 _rewardAmount, uint256 _minimumDeposit)
async start(token: string, start: number, end: number, rewardAmount: number, minimumDeposit: number): Promise<void> {
const currentBlock = await this.provider.getBlockNumber();
const rewardInWei = ethers.parseEther(rewardAmount.toString());
const minimumDepositInWei = ethers.parseEther(minimumDeposit.toString());
const startBlock = currentBlock + start;
const endBlock = startBlock + end;
console.log(`Start block: ${startBlock}`);
console.log(`End block: ${endBlock}`);
const tx = await this.contract.start(token, startBlock, endBlock, rewardInWei, minimumDepositInWei);
const receipt = await this.provider.getTransactionReceipt(tx.hash);
if (!receipt) {
console.log('Transaction failed');
return;
}
for (const log of receipt.logs) {
try {
const parsedLog = this.contract.interface.parseLog(log);
console.log(parsedLog);
} catch (error) {
console.log(error);
}
}
console.log(`Transaction hash: ${tx.hash}`);
// function start(address _token, uint256 _start, uint256 _end, uint256 _rewardAmount, uint256 _minimumDeposit)
async start(token: string, start: number, end: number, rewardAmount: number, minimumDeposit: number): Promise<void> {
const currentBlock = await this.provider.getBlockNumber();
const rewardInWei = ethers.parseEther(rewardAmount.toString());
const minimumDepositInWei = ethers.parseEther(minimumDeposit.toString());
const startBlock = currentBlock + start;
const endBlock = startBlock + end;
console.log(`Start block: ${startBlock}`);
console.log(`End block: ${endBlock}`);
const tx = await this.contract.start(token, startBlock, endBlock, rewardInWei, minimumDepositInWei);
const receipt = await this.provider.getTransactionReceipt(tx.hash);
if (!receipt) {
console.log('Transaction failed');
return;
}

async join(poolId: number, deposit: number): Promise<void> {
const depositWei = ethers.parseEther(deposit.toString());
const tx = await this.contract.join(poolId, depositWei);
console.log(`Transaction hash: ${tx.hash}`);
for (const log of receipt.logs) {
try {
const parsedLog = this.contract.interface.parseLog(log);
console.log(parsedLog);
} catch (error) {
console.log(error);
}
}
console.log(`Transaction hash: ${tx.hash}`);
}

async withdraw(poolId: number): Promise<void> {
const tx = await this.contract.withdraw(poolId);
console.log(`Transaction hash: ${tx.hash}`);
}
async join(poolId: number, deposit: number): Promise<void> {
const depositWei = ethers.parseEther(deposit.toString());
const tx = await this.contract.join(poolId, depositWei);
console.log(`Transaction hash: ${tx.hash}`);
}

async claim(poolId: number): Promise<void> {
const tx = await this.contract.claim(poolId);
console.log(`Transaction hash: ${tx.hash}`);
}
async withdraw(poolId: number): Promise<void> {
const tx = await this.contract.withdraw(poolId);
console.log(`Transaction hash: ${tx.hash}`);
}

async withdrawProtocolFee(poolId: number): Promise<void> {
const tx = await this.contract.withdrawProtocolFee(poolId);
console.log(`Transaction hash: ${tx.hash}`);
}
async claim(poolId: number): Promise<void> {
const tx = await this.contract.claim(poolId);
console.log(`Transaction hash: ${tx.hash}`);
}

getAddress(): string {
return REWARD_POOL_ADDRESS;
}
async withdrawProtocolFee(poolId: number): Promise<void> {
const tx = await this.contract.withdrawProtocolFee(poolId);
console.log(`Transaction hash: ${tx.hash}`);
}

}
getAddress(): string {
return REWARD_POOL_ADDRESS;
}
}
54 changes: 27 additions & 27 deletions src/TokenERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@ import ERC20Abi from './abi/ERC20.json';
// Happy Cats 0x161A73333250907C5Ce79c6D785C898Ffb2d6a85

export class TokenERC20 {
rpcUrl: string;
wallet: ethers.Wallet;
provider: ethers.JsonRpcProvider;
address: string;
contract: ethers.Contract;
rpcUrl: string;
wallet: ethers.Wallet;
provider: ethers.JsonRpcProvider;
address: string;
contract: ethers.Contract;

constructor(rpcUrl: string, wallet: ethers.Wallet, provider: ethers.JsonRpcProvider, address: string) {
this.rpcUrl = rpcUrl;
this.wallet = wallet;
this.provider = provider;
this.address = address;
this.contract = new ethers.Contract(address, ERC20Abi, wallet);
}
constructor(rpcUrl: string, wallet: ethers.Wallet, provider: ethers.JsonRpcProvider, address: string) {
this.rpcUrl = rpcUrl;
this.wallet = wallet;
this.provider = provider;
this.address = address;
this.contract = new ethers.Contract(address, ERC20Abi, wallet);
}

async name(): Promise<string> {
const name = await this.contract.name();
return name;
}
async name(): Promise<string> {
const name = await this.contract.name();
return name;
}

async balance(wallet: string): Promise<string> {
const balance = await this.contract.balanceOf(wallet);
const balanceEth = ethers.formatEther(balance);
return balanceEth;
}
async balance(wallet: string): Promise<string> {
const balance = await this.contract.balanceOf(wallet);
const balanceEth = ethers.formatEther(balance);
return balanceEth;
}

async approve(spender: string, amount: number): Promise<void> {
const amountInWei = ethers.parseEther(amount.toString());
const tx = await this.contract.approve(spender, amountInWei);
console.log(`Transaction hash: ${tx.hash}`);
}
}
async approve(spender: string, amount: number): Promise<void> {
const amountInWei = ethers.parseEther(amount.toString());
const tx = await this.contract.approve(spender, amountInWei);
console.log(`Transaction hash: ${tx.hash}`);
}
}
Loading

0 comments on commit bba95ef

Please sign in to comment.