Skip to content

Instantly share code, notes, and snippets.

View merlox's full-sized avatar
😄
Building great things together!

merlox merlox

😄
Building great things together!
View GitHub Profile
@merlox
merlox / jupyter-swap.js
Created February 18, 2024 21:38
Here's how to make a swap programmatically in Jupyter for Solana. It works for me.
// Slippage is defined in bps which means 100 is 1% so we gotta multiply by 100
const getAmountOutJupyter = async (tokenA, tokenB, amount, slippage) => {
const url = `https://quote-api.jup.ag/v6/quote?inputMint=${tokenA}&outputMint=${tokenB}&amount=${Number(amount).toFixed(0)}&slippageBps=${slippage*100}`
let quote = null
try {
quote = await (await fetch(url)).json()
if (!quote) {
console.error('unable to quote')
return null
}
// This is a basic uniswap frontrunning MEV bot
// Made by Merunas follow me on youtube to see how to use it and edit it: https://www.youtube.com/channel/UCJInIwgW1duAEnMHHxDK7XQ
// 1. Setup ethers, required variables, contracts and start function
const { Wallet, ethers } = require('ethers')
const { FlashbotsBundleProvider, FlashbotsBundleResolution } = require('@flashbots/ethers-provider-bundle')
// 1.1 Setup ABIs and Bytecodes
const UniswapAbi = [{"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_WETH","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint256","name":"amountADesired","type":"uint256"},{"internalType":"uint256","name":"amountBDesire
await client.query({
opportunities: [{
first: 100,
}, {
farm: {
slug: true,
logo: true,
},
totalValueLocked: true,
tokens: {
// 1. Import everything
import { Wallet, BigNumber, ethers, providers } from 'ethers'
const { FlashbotsBundleProvider, FlashbotsBundleResolution } = require('@flashbots/ethers-provider-bundle')
/*
Mainnet
const provider = new providers.JsonRpcProvider('https://eth-mainnet.g.alchemy.com/v2/cmHEQqWnoliAP0lgTieeUtwHi0KxEOlh')
const wsProvider = new providers.WebSocketProvider('wss://eth-mainnet.g.alchemy.com/v2/cmHEQqWnoliAP0lgTieeUtwHi0KxEOlh')
*/
{
"name": "My Generated NFT",
"description": "This is a generated NFT for testing purposes",
"external_url": "https://ipfs.io/ipfs/bafkreidhvbks723vbhipmxp4fv75yki7h2v3y3onbbnhisttg6iz3wnacq",
"image": "https://ipfs.io/ipfs/bafkreidhvbks723vbhipmxp4fv75yki7h2v3y3onbbnhisttg6iz3wnacq",
}
@merlox
merlox / NFT.sol
Last active October 10, 2022 19:11
The simplest NFT contract you'll ever find
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
contract NFT is ERC721URIStorage {
constructor(
string memory _name,
string memory _symbol,
@merlox
merlox / YieldFarmingWallet.sol
Last active June 7, 2022 22:21
The yield farming wallet with stETH
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.7.6;
pragma abicoder v2;
import "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol";
interface IV3SwapRouter is IUniswapV3SwapCallback {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
@merlox
merlox / comment-adder.js
Created March 21, 2022 15:45
Adds comments in the middle of the code. Reads from a "code.txt" file
const fs = require('fs')
const { join } = require('path')
function getFirstGroup(regexp, str) {
return Array.from(str.matchAll(regexp), m => m[1])
}
const file = fs.readFileSync(join(__dirname, 'code.txt'), 'utf-8')
const myRegex = /(.*)\n/g
let matches = file.matchAll(myRegex)
*
font-family: 'roboto'
.header
display: flex
align-items: center
.title-container
width: 100%
@merlox
merlox / final-test.js
Created February 24, 2022 23:59
final test
it("should write 3 words two times", async () => {
const deployerKeypair = anchor.web3.Keypair.generate()
const personThatPays = program.provider.wallet
// Add your test here
await program.rpc.initialize({
accounts: {
article: deployerKeypair.publicKey,
personThatPays: personThatPays.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,