Skip to content

Instantly share code, notes, and snippets.

View cleancoindev's full-sized avatar
🦦
OtterMarkets eh? *rolls eyes*

cleancoindev

🦦
OtterMarkets eh? *rolls eyes*
View GitHub Profile
const { Cert } = require('@0xcert/cert');
const { HttpProvider } = require('@0xcert/ethereum-http-provider');
const { AssetLedger } = require('@0xcert/ethereum-asset-ledger');
(async () => {
const schema = {
"$schema": "http://json-schema.org/draft-07/schema",
"description": "A digital assets that have a unique combination of different properties.",
"properties": {
@cleancoindev
cleancoindev / MyContracts.sol
Created March 24, 2020 19:22 — forked from ajb413/MyContracts.sol
This is how to supply CompounedCarbon ERC20s into the compound protocol.
contract MyContract {
event MyLog(string, uint256);
function supplyErc20ToCompound(
address _erc20Contract,
address _cErc20Contract,
uint256 _numTokensToSupply
) public returns (uint) {
// Create a reference to the underlying asset contract, like DAI.
Erc20 underlying = Erc20(_erc20Contract);
@cleancoindev
cleancoindev / supply-erc20-via-solidity.js
Created March 24, 2020 19:25 — forked from ajb413/supply-erc20-via-solidity.js
This is the script to run the supply contract into the blockchain/CompoundedCarbon protocol
const main = async function() {
console.log('Now transferring DAI from my wallet to MyContract...');
let transferResult = await daiContract.methods.transfer(
myContractAddress,
web3.utils.toHex(10e18) // 10 DAI to send to MyContract
).send({
from: myWalletAddress,
gasLimit: web3.utils.toHex(150000), // posted at compound.finance/developers#gas-costs
gasPrice: web3.utils.toHex(20000000000), // use ethgasstation.info (mainnet only)
// Mint some cDAI by sending DAI to the Compound Protocol
console.log('MyContract is now minting cDAI...');
let supplyResult = await myContract.methods.supplyErc20ToCompound(
daiMainNetAddress,
compoundCDaiContractAddress,
web3.utils.toHex(10e18) // 10 DAI to supply
).send({
from: myWalletAddress,
gasLimit: web3.utils.toHex(5000000), // posted at compound.finance/developers#gas-costs
gasPrice: web3.utils.toHex(20000000000), // use ethgasstation.info (mainnet only)
@cleancoindev
cleancoindev / supply-erc20-via-solidity.js
Created March 24, 2020 19:29 — forked from ajb413/supply-erc20-via-solidity.js
Redeem your c-Token back into underlying asset.
// Call redeem based on a cToken amount
const amount = web3.utils.toHex(cTokenBalance * 1e8);
const redeemType = true; // true for `redeem`
// Call redeemUnderlying based on an underlying amount
// const amount = web3.utils.toHex(balanceOfUnderlying);
// const redeemType = false; //false for `redeemUnderlying`
// Retrieve your asset by exchanging cTokens
console.log('Redeeming the cDAI for DAI...');
@cleancoindev
cleancoindev / sugh.sh
Created July 2, 2020 07:06 — forked from erdincay/sugh.sh
su GitHub (downloading all repositories from a given user)
#!/bin/bash
if [ -z "$1" ]; then
echo "waiting for the following arguments: username + max-page-number"
exit 1
else
name=$1
fi
if [ -z "$2" ]; then
@cleancoindev
cleancoindev / dydxFlashLoanTemplate.sol
Created January 13, 2021 06:55 — 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 }
@cleancoindev
cleancoindev / btcaud_hourly.py
Created January 13, 2021 06:57 — forked from cryptoscopia/btcaud_hourly.py
A script to fetch hourly historic price data for the last financial year for BTC/AUD, using the CryptoCompare API and save it as CSV.
from __future__ import print_function
import requests
data = []
timestamp = 1530367200 # 2018-07-01 00:00 AEST
for t in range(1530367200, 1530367200-365*24*60*60, -2001*60*60):
data = requests.get(
'https://min-api.cryptocompare.com/data/histohour?fsym=BTC&tsym=AUD&toTs=%s&limit=%s' \
% (t, min(365*24-len(data), 2000))
).json()['Data'] + data
@cleancoindev
cleancoindev / ethernalsale.js
Created February 4, 2021 00:38 — forked from alexvandesande/ethernalsale.js
This is a first draft at what could be a continuous token sale. I just wrote it and haven't tested it but it shows the proof of concept: tokens are continuously generated in any curve desired and sold for the highest bidder. Since there's a maximum token sale speed, this guarantees that sales can't end too quickly. Since the sale always starts f…
pragma solidity ^0.4.2;
contract ethernalSale {
struct order {
uint amount;
address buyer;
}
mapping (uint => order) orderBook;
mapping (address => uint) balanceOf;
/// @dev given a number get a slice of any bits, at certain offset
/// @param _n a number to be sliced
/// @param _nbits how many bits long is the new number
/// @param _offset how many bits to skip
function _sliceNumber(uint256 _n, uint256 _nbits, uint256 _offset) private pure returns (uint256) {
// mask is made by shifting left an offset number of times
uint256 mask = uint256((2**_nbits) - 1) << _offset;
// AND n with mask, and trim to max of _nbits bits
return uint256((_n & mask) >> _offset);
}