This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### PROTOCOL | |
- confirm node url: | |
ETHEREUM_NODE_MAINNET=https://eth-mainnet.alchemyapi.io/v2/ALxM6coYqWo1MUS12C4vQGTRVD0JfvYx | |
- `yarn`, `yarn compile`, `yarn build` | |
- `yarn hardhat node --export ../subgraphs/deployments/local/v4.json --hostname 0.0.0.0` | |
### SUBGRAPHS | |
- `yarn` in parent dir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public fortuneTeller(expectedPrice: PriceQueryResult) { | |
// this is my sophisticated trading strategy. you could build | |
// something more elaborate with the PriceQueryResult object passed in. | |
return Math.random() > 0.5; | |
} | |
public async makeMeRich() { | |
// call the getFundHoldings method which returns an array of holdings. | |
const balances = await this.accountingContract.getFundHoldings(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
... | |
"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", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); |
NewerOlder