Skip to content

Instantly share code, notes, and snippets.

@milk-duds-pro
milk-duds-pro / multi-structure-account-anchor.rs
Created December 5, 2021 21:29
an example showing that 1 account can have multiple different data structures
use anchor_lang::prelude::*;
declare_id!("8yBiqm4eZjDQACD5JnZrvoKB6nyE9xDh3yvMiPnWtTpL");
#[program]
pub mod multi_state_account_example {
use super::*;
pub fn create_many_faced_account_first_state(ctx: Context<CreateManyFacedAccount>, _account_bump:u8, first_hi1_to_add:u64, first_hi2_to_add:u32) -> ProgramResult {
let new_state = State::FirstState {
@noelbundick
noelbundick / README.md
Created October 14, 2021 16:15
Optimizing Rust container builds

Optimizing Rust container builds

I'm a Rust newbie, and one of the things that I've found frustrating is that the default docker build experience is extremely slow. As it downloads crates, then dependencies, then finally my app - I often get distracted, start doing something else, then come back several minutes later and forget what I was doing

Recently, I had the idea to make it a little better by combining multistage builds with some of the amazing features from BuildKit. Specifically, cache mounts, which let a build container cache directories for compilers & package managers. Here's a quick annotated before & after from a real app I encountered.

Before

This is a standard enough multistage Dockerfile. Nothing seemingly terrible or great here - just a normal build stage, and a smaller runtime stage.

const { expect } = require("chai");
describe("NFTOptions", function () {
const penguAddr = "0xBd3531dA5CF5857e7CfAA92426877b022e612cf8";
const penguOwner = "0x2c2c2F6DBe08942280d4F7626b6BAd5C11D20215";
const ids = ["2036", "4205"];
const buyer = "0xe5ee2B9d5320f2D1492e16567F36b578372B3d9F";
const erc721Abi = [
"function approve(address to, uint256 tokenId)"
@cryptoscopia
cryptoscopia / dydxFlashLoanTemplate.sol
Created October 21, 2020 06:42
A single-file simplest possible template for a contract that obtains a flash loan from dydx, does things, and pays it back.
// SPDX-License-Identifier: AGPL-3.0-or-later
// The ABI encoder is necessary, but older Solidity versions should work
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
// These definitions are taken from across multiple dydx contracts, and are
// limited to just the bare minimum necessary to make flash loans work.
library Types {
enum AssetDenomination { Wei, Par }
@yoavniran
yoavniran / ultimate-ut-cheat-sheet.md
Last active July 12, 2024 11:15
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai, Sinon, and Jest