Skip to content

Commit

Permalink
Rebuild from ground up
Browse files Browse the repository at this point in the history
  • Loading branch information
xhad committed Dec 13, 2024
1 parent 977748d commit 203f084
Show file tree
Hide file tree
Showing 48 changed files with 802 additions and 2,245 deletions.
20 changes: 0 additions & 20 deletions .dockerignore

This file was deleted.

18 changes: 1 addition & 17 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,4 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
branch = release-v4.9
[submodule "lib/contract-utils"]
path = lib/contract-utils
url = https://github.com/loreum-org/contract-utils
branch = release-v0.2
[submodule "lib/loreum-token"]
path = lib/loreum-token
url = https://github.com/loreum-org/loreum-token
[submodule "lib/loreum-nft"]
path = lib/loreum-nft
url = https://github.com/loreum-org/loreum-nft
[submodule "lib/solmate"]
path = lib/solmate
url = https://github.com/transmissions11/solmate
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
branch = release-v5.0
16 changes: 0 additions & 16 deletions dockerfile

This file was deleted.

1 change: 0 additions & 1 deletion lib/contract-utils
Submodule contract-utils deleted from 3c978f
1 change: 0 additions & 1 deletion lib/loreum-nft
Submodule loreum-nft deleted from 0a0e79
1 change: 0 additions & 1 deletion lib/loreum-token
Submodule loreum-token deleted from 470961
1 change: 0 additions & 1 deletion lib/openzeppelin-contracts-upgradeable
Submodule openzeppelin-contracts-upgradeable deleted from 3d4c0d
1 change: 0 additions & 1 deletion lib/solmate
Submodule solmate deleted from bfc9c2
4 changes: 0 additions & 4 deletions remappings.txt

This file was deleted.

11 changes: 6 additions & 5 deletions script/Chamber.s.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { Script } from "lib/forge-std/src/Script.sol";
import { Chamber } from "src/Chamber.sol";
import { console2 } from "lib/forge-std/src/console2.sol";
import {Script} from "lib/forge-std/src/Script.sol";
import {Chamber} from "src/Chamber.sol";

contract DeployChamber is Script {

address token = address(1);
address nft = address(2);

function run() external {
vm.startBroadcast();
Chamber chamberImpl = new Chamber();
Chamber chamberImpl = new Chamber(token, nft, 5);
vm.stopBroadcast();
console2.log("Chamber Implementation: ", address(chamberImpl));
}
}
37 changes: 0 additions & 37 deletions script/Create2.s.sol

This file was deleted.

19 changes: 0 additions & 19 deletions script/ERC20.s.sol

This file was deleted.

24 changes: 0 additions & 24 deletions script/ERC721.s.sol

This file was deleted.

34 changes: 0 additions & 34 deletions script/Loreum.s.sol

This file was deleted.

17 changes: 0 additions & 17 deletions script/Registry.s.sol

This file was deleted.

25 changes: 0 additions & 25 deletions script/utils/DeployProxy.sol

This file was deleted.

108 changes: 108 additions & 0 deletions src/Board.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

abstract contract Board {

string public constant version = "1";

struct Node {
uint256 tokenId;
uint256 amount;
uint256 next;
uint256 prev;
}

// Mapping from tokenId to Node
mapping(uint256 => Node) internal nodes;

// Head and tail of the list (0 represents null)
uint256 public head;
uint256 public tail;
uint256 public size;

function _getNode(uint256 tokenId) internal view returns (Node memory) {
return nodes[tokenId];
}

function _insert(uint256 tokenId, uint256 amount) internal {
Node storage newNode = nodes[tokenId];
newNode.tokenId = tokenId;
newNode.amount = amount;

if (head == 0) {
// First node
head = tokenId;
tail = tokenId;
} else {
// Find position and insert
uint256 current = head;

while (current != 0 && amount <= nodes[current].amount) {
current = nodes[current].next;
}

if (current == 0) {
// Insert at tail
nodes[tail].next = tokenId;
newNode.prev = tail;
tail = tokenId;
} else {
// Insert before current node
newNode.next = current;
newNode.prev = nodes[current].prev;

if (newNode.prev != 0) {
nodes[newNode.prev].next = tokenId;
} else {
head = tokenId;
}

nodes[current].prev = tokenId;
}
}
size++;
}

function _remove(uint256 tokenId) internal {
Node storage node = nodes[tokenId];

if (node.prev != 0) {
nodes[node.prev].next = node.next;
} else {
head = node.next;
}

if (node.next != 0) {
nodes[node.next].prev = node.prev;
} else {
tail = node.prev;
}

delete nodes[tokenId];
size--;
}

function _reposition(uint256 tokenId) internal {
uint256 amount = nodes[tokenId].amount;
_remove(tokenId);
_insert(tokenId, amount);
}

// View functions for the leaderboard
function _getTop(
uint256 count
) internal view returns (uint256[] memory, uint256[] memory) {
uint256 resultCount = count > size ? size : count;
uint256[] memory tokenIds = new uint256[](resultCount);
uint256[] memory amounts = new uint256[](resultCount);

uint256 current = head;
for (uint256 i = 0; i < resultCount; i++) {
tokenIds[i] = current;
amounts[i] = nodes[current].amount;
current = nodes[current].next;
}

return (tokenIds, amounts);
}
}
Loading

0 comments on commit 203f084

Please sign in to comment.