Skip to content

Instantly share code, notes, and snippets.

@erin-koen
Last active May 5, 2020 13:35
Show Gist options
  • Save erin-koen/bf9c605eb37a840c98a9dd6305cc3357 to your computer and use it in GitHub Desktop.
Save erin-koen/bf9c605eb37a840c98a9dd6305cc3357 to your computer and use it in GitHub Desktop.
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.');
}
const trading = new Trading(environment, routes.trading);
const accounting = new Accounting(environment, routes.accounting);
const adapterAddress = environment.deployment.melon.addr.UniswapAdapter;
const adapter = await UniswapTradingAdapter.create(environment, adapterAddress, trading);
const factoryAddress = environment.deployment.uniswap.addr.UniswapFactory;
const factory = new UniswapFactory(environment, factoryAddress);
const tokenOne = environment.getToken(tokenOneSymbol);
const tokenTwo = environment.getToken(tokenTwoSymbol);
return new this(environment, account, hub, trading, accounting, adapter, factory, tokenOne, tokenTwo);
}
private constructor(
public readonly environment: DeployedEnvironment,
public readonly account: string,
public readonly hubContract: Hub,
public readonly tradingContract: Trading,
public readonly accountingContract: Accounting,
public readonly uniswapAdapterContract: UniswapTradingAdapter,
public readonly uniswapFactoryContract: UniswapFactory,
public readonly tokenOne: TokenDefinition,
public readonly tokenTwo: TokenDefinition
) {}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment