Skip to content

Instantly share code, notes, and snippets.

@devxtoshi
devxtoshi / dydxFlashLoanTemplate.sol
Created May 6, 2022 01:27 — forked from cryptoscopia/dydxFlashLoanTemplate.sol
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 }
@devxtoshi
devxtoshi / stripe-proration.php
Created March 10, 2023 01:40 — forked from cballou/stripe-proration.php
Calculate a proration percentage given the current timestamp and a current billing period
<?php
/**
* Handle calculating a percentage/fraction (proration) we should charge the
* user for based on the current day of the month before their next bill cycle.
* To use yourself, implement a getSubscription method which returns an object
* containing current_period_start and current_period_end DateTime objects.
*
* @access public
* @return float
@devxtoshi
devxtoshi / stripe-webhook.js
Created March 31, 2023 06:06 — forked from gragland/stripe-webhook.js
Next.js Stripe Webhook from divjoy.com
const getRawBody = require("raw-body");
const { updateUserByCustomerId } = require("./_db.js");
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY, {
apiVersion: process.env.STRIPE_API_VERSION,
});
// Disable next.js body parsing (stripe needs the raw body to validate the event)
export const config = {
api: {