Compare commits

..

No commits in common. "7a32129f7e0ef920a7066aeb741967e9bf9f2273" and "49b7110a6c38f9b85437b0b3b0ba2446f8c078b9" have entirely different histories.

16 changed files with 81 additions and 139 deletions

3
.gitignore vendored
View File

@ -1,6 +1,3 @@
# Address
/app/contract_address.ts
# Compiler files
cache/
out/

View File

@ -20,8 +20,6 @@ This is so time gets set on the local chain, otherwise you will start at 0 time
#### 3. 2. Point Metamask to Anvil network for local dev
#### 3. 3. Change `app/contract_address.ts` to match your program address if needed
### 4. Local development requires mining blocks by hand
Call `cast rpc anvil_mine` to mine next block, otherwise it wont ever progress and time "stands still" as far as the game is concerned

5
app/.gitignore vendored
View File

@ -1,7 +1,4 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files
# address
contract_address.ts
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules

View File

@ -1,4 +0,0 @@
const contractAddress = "0xbd06B0878888bf4c6895704fa603a5ADf7e65c66";
export default contractAddress

View File

@ -8,12 +8,14 @@ const calculateBalance = (balance: bigint, perSecond: bigint, lastRaidedAt: bigi
(new Date()).getTime() - parseInt(lastRaidedAt.toString()) * 1000;
return (
balance +
(BigInt(millisecondsSinceLastRaid) * perSecond
(BigInt(millisecondsSinceLastRaid) * (perSecond * BigInt(10000) /* decimals */)
/ BigInt(1000) /* deduct milliseconds*/))
}
export const toReadable = (value: bigint) => {
export const toReadable = (value: bigint, applyTokenDivision?: boolean) => {
if (applyTokenDivision) {
value = value / BigInt(10000);
}
const suffixes = [
{ value: BigInt('1000'), suffix: 'thousand' },
{ value: BigInt('1000000'), suffix: 'million' },
@ -35,6 +37,8 @@ export const toReadable = (value: bigint) => {
{ value: BigInt('1000000000000000000000000000000000000000000000000000000'), suffix: 'septendecillion' },
];
console.log(value)
for (let i = 0; i < suffixes.length; i++) {
if (value < suffixes[i].value) {
if (i == 0) {
@ -62,8 +66,8 @@ const Counter = () => {
balance,
army?.profit_per_second ?? BigInt(0),
player?.last_raided_at ?? BigInt(0)
));
availableBalance.current = toReadable(balance);
), true);
availableBalance.current = toReadable(balance, true);
render();
}, 100);
return () => clearInterval(tickInterval)

View File

@ -25,6 +25,7 @@ const Header = () => {
const perSecondParagraph = useMemo(() => {
const perSecond = toReadable(army?.profit_per_second ?? BigInt(0))
console.log(perSecond, army?.profit_per_second)
return (isRegistered) ?
<p className={styles.counter_per_seconds}>per second: {perSecond}</p>
: null

View File

@ -26,7 +26,7 @@ const Home: NextPage = () => {
</main>
<footer className={styles.footer}>
Made with by your frens at 😈 Slay the Moloch team for Cohort VII of <a href="https://www.raidguild.org/" target="blank">RaidGuild</a>
Made with by your fren mic0
</footer>
</div>
);

View File

@ -2,8 +2,8 @@ import React, { createContext, ReactNode, useCallback, useContext, useEffect } f
import { useAccount, useReadContract, useWriteContract } from 'wagmi'
import contractAbi from "../../../out/RaidGeld.sol/RaidGeld.json"
import { parseEther } from 'viem'
import contractAddress from '../../contract_address'
const contractAddress = "0xbd06B0878888bf4c6895704fa603a5ADf7e65c66"
const abi = contractAbi.abi
export interface Player {
@ -91,7 +91,7 @@ const PlayerProvider = ({ children }: { children: ReactNode }) => {
}
});
console.log(player, army)
console.log(player)
const register = useCallback(() => {
writeContract({

View File

@ -21,10 +21,19 @@
}
.footer {
margin-top: 2rem;
display: flex;
flex: 1;
padding: 2rem 0;
border-top: 1px solid #eaeaea;
text-align: center;
justify-content: center;
align-items: center;
}
.footer a {
display: flex;
justify-content: center;
align-items: center;
flex-grow: 1;
}
.title a {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
struct Raider {
uint16 level;
}

View File

@ -4,13 +4,16 @@ pragma solidity ^0.8.13;
import {Army} from "../src/RaidGeldStructs.sol";
library RaidGeldUtils {
uint256 public constant PRECISION = 10000;
uint256 constant BASE_PRICE = 380000;
uint256 constant PRICE_FACTOR = 11500;
uint256 constant APPRENTICE_PROFIT = 61000;
uint256 constant ANOINTED_PROFIT = 6 * 64000;
uint256 constant CHAMPION_PROFIT = 67000 * 61000 * 64000/ PRECISION / PRECISION;
function calculateUnitPrice(uint8 unit, uint16 currentLevel, uint16 units) internal pure returns (uint256) {
require(unit <= 3, "No matching unit found");

View File

@ -6,7 +6,7 @@ import {Army, Raider} from "../src/RaidGeld.sol";
import "../src/RaidGeldUtils.sol";
contract raid_geldTest is Test {
function test_0_unit_price() public pure {
function test_0_unit_price() public {
// buying 1 unit of moloch_denier
uint256 basePriceMolochDenier = RaidGeldUtils.calculateUnitPrice(0, 0, 1);
assertEq(basePriceMolochDenier, RaidGeldUtils.BASE_PRICE);
@ -47,8 +47,11 @@ contract raid_geldTest is Test {
profit_per_second: 0 // irrelevant for this test
});
profits_per_second = RaidGeldUtils.calculateProfitsPerSecond(army);
uint256 expected = _dLvl * RaidGeldUtils.PRECISION + _apLvl * RaidGeldUtils.APPRENTICE_PROFIT
+ _anLvl * RaidGeldUtils.ANOINTED_PROFIT + _cLvl * RaidGeldUtils.CHAMPION_PROFIT;
uint256 expected =
_dLvl * RaidGeldUtils.PRECISION +
_apLvl * RaidGeldUtils.APPRENTICE_PROFIT +
_anLvl * RaidGeldUtils.ANOINTED_PROFIT +
_cLvl * RaidGeldUtils.CHAMPION_PROFIT;
assertEq(profits_per_second, expected);
}
}