Skip to content

Instantly share code, notes, and snippets.

const mask = (w) => (1n << w) - 1n;
const bnToHex = (bn) => {
let s = bn.toString(16);
if(bn % 2n === 0n){
s = `0${s}`;
}
return `0x${s}`;
}
const CLAIM_FLAGS_WIDTH = 8n;
@kbahr
kbahr / HexBars.txt
Created February 23, 2020 03:42
HTML, CSS, and Javascript for hexagonal progress bars with the HEX color gradient
<!-- HTML for hex progress bar -->
<div id="wrapper" class="center">
<svg class="hex-progress noselect" data-progress="87.5" x="0px" y="0px" viewBox="0 0 776 628">
<path class="track" d="M723 314L543 625.77 183 625.77 3 314 183 2.23 543 2.23 723 314z" ></path>
<path class="fill" d="M723 314L543 625.77 183 625.77 3 314 183 2.23 543 2.23 723 314z" stroke="url(#cl1)"></path>
<text class="value" x="50%" y="61%">0%</text>
<text class="text" x="50%" y="122%">Staked</text>
</svg>
@kbahr
kbahr / HEXLottoProposal.sol
Created February 21, 2020 21:54
Proposed solution to the lotto entry traversal issue
pragma solidity >=0.5.16
contract HEXLotto {
// I didn't see where hexAmount was ever used
struct Entry {
uint256 ticketNumber; // could be uint96 to save space (12bytes + 20bytes address)
address buyer;
}
@kbahr
kbahr / HexUtilities.sol
Last active January 18, 2024 13:25
HEX utilities in solidity to get stake values
pragma solidity ^0.5.12;
import "./HEX.sol";
contract HexUtilities {
struct StakeStore {
uint40 stakeId;
uint72 stakedHearts;
uint72 stakeShares;
@kbahr
kbahr / BasicUtilities.js
Last active December 29, 2022 14:40
HEX pull interest to date
const Web3 = require('web3');
const compiledContractABI = require('./HEX.abi.json');
const hexAddr = "0x2b591e99afE9f32eAA6214f7B7629768c40Eeb39";
const findStakeAndIndex = async (addr, stakeId) => {
let stakes = await hex.stakeList(addr);
for(let i = 0; i < stakes.length; i++){
if(stakes[i].stakeId === stakeId){
@kbahr
kbahr / ReferralContract.sol
Created January 6, 2020 05:39
A HEX/ETH "referral" contract that takes an erc20 token address (made for HEX, but any should work), a set of splitter addresses and their percentages. It will split ETH and ERC20 tokens by the addresses' percentages
pragma solidity ^0.5.12;
import "./HEX.sol"; // TODO: Windows file separator
contract ReferralSplitter {
event DistributedShares(
uint40 timestamp,
address indexed memberAddress,
uint256 amount

Keybase proof

I hereby claim:

  • I am kbahr on github.
  • I am kylebahr (https://keybase.io/kylebahr) on keybase.
  • I have a public key ASD4gYsgeXmvAEZ-ohOdOISGzYxZ-oKOsARmRCWM2606QQo

To claim this, I am signing this object: