Skip to content

Instantly share code, notes, and snippets.

Verifying my Blockstack ID is secured with the address 1ENdTF2NUiYBM2ZV5J1mbNd3CowT9YLqro https://explorer.blockstack.org/address/1ENdTF2NUiYBM2ZV5J1mbNd3CowT9YLqro

Keybase proof

I hereby claim:

  • I am erin-koen on github.
  • I am eek637 (https://keybase.io/eek637) on keybase.
  • I have a public key ASDKimc8bOEIcqP7Oa4CLzVHf8wRWu7XpoB41E3qKKJKrAo

To claim this, I am signing this object:

@erin-koen
erin-koen / MelonBot.constructor.ts
Last active May 5, 2020 13:35
The Melon Bot's Constructor
export class UniswapBot {
public static async create(hubAddress: string, tokenOneSymbol: string, tokenTwoSymbol: string) {
const environment = createEnvironment();
const hub = new Hub(environment, hubAddress);
const routes = await hub.getRoutes();
const manager = await hub.getManager();
const account = (await environment.client.getAccounts())[0];
if (!sameAddress(manager, account)) {
throw new Error('You are not the manager of this fund.');
@erin-koen
erin-koen / MelonBot.getBalances.ts
Last active May 1, 2020 15:24
The Melon Bot's Balance Method
public async getBalances() {
// find the fund's accounting address
const accountingAddress = (await this.hub.getRoutes()).accounting;
// and instantiate a js representation of the contract
const accounting = new Accounting(this.environment, accountingAddress);
// to call the getFundHoldings method
const fundHoldings = await accounting.getFundHoldings();
@erin-koen
erin-koen / MelonBot.getPrice.ts
Last active May 1, 2020 15:23
The Melon Bot's Price Query
public async getPrice(baseCurrency: TokenDefinition, quoteCurrency: TokenDefinition, baseQuantity: BigNumber) {
// Every uniswap exchange is WETH/someToken, and identified by the non-weth token
const exchangeToken = baseCurrency.symbol === 'WETH' ? quoteCurrency : baseCurrency;
// call the method to find the address
const exchangeAddress = await this.uniswapFactoryContract.getExchange(exchangeToken.address);
// instantiate the exchange contract
const exchange = new UniswapExchange(this.environment, exchangeAddress);
@erin-koen
erin-koen / MelonBot.makeTrade.ts
Last active April 30, 2020 21:27
The Melon Bot's Trade Method
public async makeTransaction(priceInfo: PriceQueryResult){
// adjust the target amount of token to buy
const slippage = 0.97;
// use the price query results to construct the uniswap order argument object
const orderArgs = {
makerQuantity: priceInfo.sizeInQuote.integerValue().multipliedBy(slippage),
takerQuantity: priceInfo.sizeInBase.integerValue(),
makerAsset: priceInfo.quoteCurrency.address,
takerAsset: priceInfo.baseCurrency.address,
@erin-koen
erin-koen / melonBot.package.json
Last active August 11, 2020 03:02
The Melon Bot's package.json
{
...
"scripts": {
"dev": "cross-env NODE_ENV=development ts-node --require dotenv-extended/config --transpile-only src"
},
"dependencies": {
"@melonproject/melonjs": "^1.0.1",
"axios": "^0.19.2",
"bignumber.js": "^9.0.0",
"web3-core": "^2.0.0-alpha.1",
@erin-koen
erin-koen / MelonBot.environment.ts
Last active April 30, 2020 21:04
The Melon Bot's Environment Configuration
import { DeployedEnvironment } from '@melonproject/melonjs';
import { Eth } from 'web3-eth';
import { HttpProvider, WebsocketProvider, HttpProviderOptions, WebsocketProviderOptions } from 'web3-providers';
import deployment from '../deployments/mainnet-deployment.json';
function createProvider(endpoint: string, options?: HttpProviderOptions | WebsocketProviderOptions) {
if (endpoint.startsWith('https://') || endpoint.startsWith('http://')) {
return new HttpProvider(endpoint, options as HttpProviderOptions);
}
@erin-koen
erin-koen / MelonBot.ts
Last active February 27, 2021 16:24
The Melon Fund Uniswap Bot
export class UniswapBot {
public static async create(hubAddress: string, tokenOneSymbol: string, tokenTwoSymbol: string) {
const environment = createEnvironment();
const hub = new Hub(environment, hubAddress);
const routes = await hub.getRoutes();
const manager = await hub.getManager();
const account = (await environment.client.getAccounts())[0];
@erin-koen
erin-koen / MelonBot.runScript.ts
Last active April 30, 2020 21:32
A script to run the Melon Bot
async function run(bot: UniswapBot) {
try {
console.log('CONSULTING THE ORACLE ==> ');
const transaction = await bot.makeMeRich();
if (!transaction) {
console.log('NO TRADING BY ORDER OF THE ORACLE');
} else {
console.log('THE ORACLE SAYS TO TRADE');