0x09cd18d17c48a9e5f7919dbb8267cbc0f9c75e95a3c94f9c4f910edaf90c2db6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type GraphGenerator<T> = Iterable<[T, T?]>; | |
interface Edges<T> { | |
pred: T[]; | |
succ: T[]; | |
} | |
export function toposort<T, G extends GraphGenerator<T>>(graph: G): T[] { | |
const sorted = new Set<T>(); | |
const nodes = new Map<T, Edges<T>>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.9; | |
// Unlike the string type, ShortString is a value type that can be made immutable. | |
// It supports strings of at most 32 bytes and assumes they don't contain null bytes. | |
type ShortString is bytes32; | |
error StringTooLong(string s); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.4; | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol"; | |
contract MyTokenV1 is Initializable, ERC20Upgradeable { | |
function initialize() initializer public { | |
__ERC20_init("MyToken", "MTK"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { Subscriber } from 'svelte/store'; | |
export function store<T>(start: () => T, stop?: () => void) { | |
const subscribers = new Set<Subscriber<T>>(); | |
let value: T; | |
function notify() { | |
for (const fn of subscribers) { | |
fn(value); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/utils/math/Math.sol"; | |
struct Accumulator { | |
uint concrete; | |
uint virtualRate; | |
uint virtualSince; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned divlu(unsigned u1, unsigned u0, unsigned v, | |
unsigned *r) { | |
const unsigned b = 65536; // Number base (16 bits). | |
unsigned un1, un0, // Norm. dividend LSD's. | |
vn1, vn0, // Norm. divisor digits. | |
q1, q0, // Quotient digits. | |
un32, un21, un10, // Divident digit pairs. | |
rhat; // A remainder. | |
int s; // Shift amount for norm. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nlz(uint x) pure returns (uint n) { | |
uint y; | |
n = 256; | |
y = x >> 128; if (y != 0) { n = n - 128; x = y; } | |
y = x >> 64; if (y != 0) { n = n - 64; x = y; } | |
y = x >> 32; if (y != 0) { n = n - 32; x = y; } | |
y = x >> 16; if (y != 0) { n = n - 16; x = y; } | |
y = x >> 8; if (y != 0) { n = n - 8; x = y; } | |
y = x >> 4; if (y != 0) { n = n - 4; x = y; } | |
y = x >> 2; if (y != 0) { n = n - 2; x = y; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
error Overflow(); | |
uint constant b = 2 ** 128; | |
/// Divides a two word number by one word number. | |
/// Returns q and r such that u1 << 256 + u0 = q * v + r. | |
function divlu(uint u1, uint u0, uint v) pure returns (uint q, uint r) { unchecked { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
error Overflow(); | |
/// Multiply-and-divide without intermediate overflow. | |
/// @return r = (x * y) / d | |
function mulDiv(uint x, uint y, uint d) pure returns (uint r) { unchecked { | |
(uint z1, uint z0) = mul_1_1_2(x, y); | |
(r,) = div_2_1_1(z1, z0, d); |