Skip to content

Commit

Permalink
re-write this monorepo to point to generation software - fix up claim…
Browse files Browse the repository at this point in the history
…ed by using rpc calls to
  • Loading branch information
chuckbergeron committed Jul 4, 2023
1 parent af00077 commit 54d5c11
Show file tree
Hide file tree
Showing 60 changed files with 121 additions and 152 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Monorepo grouping PoolTogether hyperstructure (v5) bots as OpenZeppelin Defender

## Installation

1. This library uses `yalc` to manage local dependencies. You will need to clone the `v5-utils-js` repo and publish it (you can publish it using `yarn start` after `yarn install` in the `v5-utils-js` directory).
1. This library uses `yalc` to manage local dependencies. You will need to clone the `pt-v5-utils-js` repo and publish it (you can publish it using `yarn start` after `yarn install` in the `pt-v5-utils-js` directory).

2. Following that, make sure to run `yarn yalcadd` before installing to setup local dependencies.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"lerna": "lerna",
"publish": "npm run lerna publish --conventional-commits --exact --include-merged-tags",
"yalcadd": "npx yalc add @pooltogether/v5-utils-js --pure"
"yalcadd": "npx yalc add @generationsoftware/pt-v5-utils-js --pure"
},
"devDependencies": {
"@types/node": "18.11.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-liquidator/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @pooltogether/v5-autotasks-arb-liquidator
# @generationsoftware/pt-v5-autotasks-arb-liquidator

![title image for PoolTogether Arbitrage Liquidator Bot](https://github.com/pooltogether/v5-autotasks/raw/main/packages/arb-liquidator/arb-liquidator-img.png "title image for PoolTogether Arbitrage Liquidator Bot")

Expand Down
2 changes: 1 addition & 1 deletion packages/arb-liquidator/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@pooltogether/v5-autotasks-arb-liquidator",
"name": "@generationsoftware/pt-v5-autotasks-arb-liquidator",
"version": "0.0.1",
"description": "Autotask to check if there are arbitrage profits from a network's liquidator.",
"author": "PoolTogether Inc.",
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-liquidator/script/chooseNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import esMain from 'es-main';
import Configstore from 'configstore';

import { askChainId } from '@pooltogether/v5-autotasks-library';
import { askChainId } from '@generationsoftware/pt-v5-autotasks-library';

import pkg from '../package.json';

Expand Down
4 changes: 2 additions & 2 deletions packages/arb-liquidator/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { ethers } from 'ethers';
import {
liquidatorArbitrageSwap,
ArbLiquidatorConfigParams,
} from '@pooltogether/v5-autotasks-library';
import { downloadContractsBlob } from '@pooltogether/v5-utils-js';
} from '@generationsoftware/pt-v5-autotasks-library';
import { downloadContractsBlob } from '@generationsoftware/pt-v5-utils-js';
import { Relayer } from 'defender-relay-client';
import { DefenderRelayProvider, DefenderRelaySigner } from 'defender-relay-client/lib/ethers';

Expand Down
4 changes: 2 additions & 2 deletions packages/arb-liquidator/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Relayer } from 'defender-relay-client';
import { ethers } from 'ethers';
import { Provider } from '@ethersproject/providers';
import { DefenderRelayProvider, DefenderRelaySigner } from 'defender-relay-client/lib/ethers';
import { downloadContractsBlob } from '@pooltogether/v5-utils-js';
import { downloadContractsBlob } from '@generationsoftware/pt-v5-utils-js';
import {
liquidatorArbitrageSwap,
ArbLiquidatorConfigParams,
} from '@pooltogether/v5-autotasks-library';
} from '@generationsoftware/pt-v5-autotasks-library';

const handlerLoadParams = (
signer: Provider | DefenderRelaySigner,
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-liquidator/src/helpers/questions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chalk from 'chalk';
import { DistinctQuestion } from 'inquirer';

import { populateConfig } from '@pooltogether/v5-autotasks-library';
import { populateConfig } from '@generationsoftware/pt-v5-autotasks-library';
import Configstore from 'configstore';

interface PACKAGE_CONFIG {
Expand Down
4 changes: 2 additions & 2 deletions packages/arb-liquidator/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default defineConfig((opt) => {
},
noExternal: [
'inquirer',
'@pooltogether/v5-autotasks-library',
'@pooltogether/v5-utils-js',
'@generationsoftware/pt-v5-autotasks-library',
'@generationsoftware/pt-v5-utils-js',
'ethereum-multicall',
'configstore',
],
Expand Down
2 changes: 1 addition & 1 deletion packages/draw-beacon/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @pooltogether/v5-autotasks-draw-beacon
# @generationsoftware/pt-v5-autotasks-draw-beacon

PoolTogether hyperstructure (v5) OpenZeppelin Defender autotask to start and complete a draw.

Expand Down
4 changes: 2 additions & 2 deletions packages/draw-beacon/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@pooltogether/v5-autotasks-draw-beacon",
"name": "@generationsoftware/pt-v5-autotasks-draw-beacon",
"version": "0.0.1",
"description": "Autotask to start and complete a draw.",
"author": "PoolTogether Inc.",
Expand Down Expand Up @@ -45,4 +45,4 @@
"rollup-plugin-inject-process-env": "1.3.1",
"ts-node": "10.9.1"
}
}
}
4 changes: 2 additions & 2 deletions packages/draw-beacon/src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Relayer, RelayerParams } from 'defender-relay-client';
import { DefenderRelayProvider, DefenderRelaySigner } from 'defender-relay-client/lib/ethers';
import { downloadContractsBlob } from '@pooltogether/v5-utils-js';
import { drawBeaconHandleDrawStartAndComplete } from '@pooltogether/v5-autotasks-library';
import { downloadContractsBlob } from '@generationsoftware/pt-v5-utils-js';
import { drawBeaconHandleDrawStartAndComplete } from '@generationsoftware/pt-v5-autotasks-library';

export async function handler(event: RelayerParams) {
const provider = new DefenderRelayProvider(event);
Expand Down
2 changes: 1 addition & 1 deletion packages/draw-beacon/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from 'tsup';

export default defineConfig({
noExternal: ['@pooltogether/v5-autotasks-library', 'ethereum-multicall'],
noExternal: ['@generationsoftware/pt-v5-autotasks-library', 'ethereum-multicall'],
format: 'cjs',
entry: ['src/handler.ts'],
splitting: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/draw-reserve/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @pooltogether/v5-autotasks-draw-reserve
# @generationsoftware/pt-v5-autotasks-draw-reserve

![title image for PoolTogether Draw Reserve Sweeper Bot](https://github.com/pooltogether/v5-autotasks/raw/main/packages/draw-reserve/prize-claim-img.png "title image for PoolTogether Draw Reserve Sweeper Bot")

Expand Down
2 changes: 1 addition & 1 deletion packages/draw-reserve/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@pooltogether/v5-autotasks-draw-reserve",
"name": "@generationsoftware/pt-v5-autotasks-draw-reserve",
"version": "0.0.1",
"description": "Autotask to automatically sweep draw reserve for bots who start & complete draws for the PoolTogether Hyperstructure (v5).",
"author": "PoolTogether Inc.",
Expand Down
2 changes: 1 addition & 1 deletion packages/draw-reserve/script/chooseNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import esMain from 'es-main';
import Configstore from 'configstore';

import { askChainId } from '@pooltogether/v5-autotasks-library';
import { askChainId } from '@generationsoftware/pt-v5-autotasks-library';

import pkg from '../package.json';

Expand Down
2 changes: 1 addition & 1 deletion packages/draw-reserve/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Configstore from 'configstore';
import figlet from 'figlet';
import chalk from 'chalk';
import { ethers } from 'ethers';
import { DrawReserveConfigParams } from '@pooltogether/v5-autotasks-library';
import { DrawReserveConfigParams } from '@generationsoftware/pt-v5-autotasks-library';
import { DefenderRelayProvider, DefenderRelaySigner } from 'defender-relay-client/lib/ethers';

import { askQuestions } from './helpers/questions';
Expand Down
2 changes: 1 addition & 1 deletion packages/draw-reserve/src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from 'ethers';
import { RelayerParams } from 'defender-relay-client';
import { DrawReserveConfigParams } from '@pooltogether/v5-autotasks-library';
import { DrawReserveConfigParams } from '@generationsoftware/pt-v5-autotasks-library';
import { DefenderRelayProvider, DefenderRelaySigner } from 'defender-relay-client/lib/ethers';

import { populateTransaction, processPopulatedTransaction } from './transactions';
Expand Down
2 changes: 1 addition & 1 deletion packages/draw-reserve/src/helpers/questions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chalk from 'chalk';
import inquirer, { DistinctQuestion } from 'inquirer';

import { populateConfig } from '@pooltogether/v5-autotasks-library';
import { populateConfig } from '@generationsoftware/pt-v5-autotasks-library';
import Configstore from 'configstore';

interface PACKAGE_CONFIG {
Expand Down
4 changes: 2 additions & 2 deletions packages/draw-reserve/src/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import chalk from 'chalk';
import { PopulatedTransaction } from '@ethersproject/contracts';
import { RelayerParams } from 'defender-relay-client';
import { downloadContractsBlob } from '@pooltogether/v5-utils-js';
import { downloadContractsBlob } from '@generationsoftware/pt-v5-utils-js';
import {
getWithdrawReserveTx,
printAsterisks,
printSpacer,
} from '@pooltogether/v5-autotasks-library';
} from '@generationsoftware/pt-v5-autotasks-library';
import { Relayer } from 'defender-relay-client';

export const populateTransaction = async (params, readProvider): Promise<PopulatedTransaction> => {
Expand Down
4 changes: 2 additions & 2 deletions packages/draw-reserve/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default defineConfig((opt) => {
},
noExternal: [
'inquirer',
'@pooltogether/v5-autotasks-library',
'@pooltogether/v5-utils-js',
'@generationsoftware/pt-v5-autotasks-library',
'@generationsoftware/pt-v5-utils-js',
'ethereum-multicall',
'configstore',
],
Expand Down
10 changes: 5 additions & 5 deletions packages/library/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# @pooltogether/v5-autotasks-library
# @generationsoftware/pt-v5-autotasks-library

PoolTogether hyperstructure (v5) supporting functions for the bots.

## Install

```
yarn add @pooltogether/v5-autotasks-library
yarn add @generationsoftware/pt-v5-autotasks-library
```

or

```
npm install @pooltogether/v5-autotasks-library
npm install @generationsoftware/pt-v5-autotasks-library
```

## Usage

You can use this library in your own code, for instance if you would rather not use OpenZeppelin Defender for your automated/cron-based bots. Here's an example:

```ts
import { downloadContractsBlob } from "@pooltogether/v5-utils-js";
import { executeClaimerProfitablePrizeTxs } from "@pooltogether/v5-autotasks-library";
import { downloadContractsBlob } from "@generationsoftware/pt-v5-utils-js";
import { executeClaimerProfitablePrizeTxs } from "@generationsoftware/pt-v5-autotasks-library";

interface Params {
contracts: ContractsBlob;
Expand Down
8 changes: 4 additions & 4 deletions packages/library/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@pooltogether/v5-autotasks-library",
"version": "0.0.1-beta.6",
"description": "Library of shared utils to run PoolTogether hyperstructure (v5) autotasks.",
"name": "@generationsoftware/pt-v5-autotasks-library",
"version": "0.0.1-beta.7",
"description": "Library of shared utils to run PoolTogether v5 hyperstructure autotasks.",
"author": "PoolTogether Inc.",
"homepage": "https://github.com/pooltogether/v5-autotasks/packages/library/README.md",
"license": "ISC",
Expand All @@ -27,7 +27,7 @@
"url": "https://github.com/pooltogether/v5-autotasks/issues"
},
"dependencies": {
"@pooltogether/v5-utils-js": "0.0.1-beta.23",
"@generationsoftware/pt-v5-utils-js": "0.0.1-beta.27",
"chalk": "^4.1.2",
"defender-relay-client": "1.39.0",
"ethers": "5.7.2",
Expand Down
28 changes: 14 additions & 14 deletions packages/library/src/claimerProfitablePrizeTxs.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ethers, BigNumber, Contract } from 'ethers';
import { Provider } from '@ethersproject/providers';
import { Claim, getContract } from '@pooltogether/v5-utils-js';
import { Claim, getContract, flagClaimedRpc } from '@generationsoftware/pt-v5-utils-js';
import { Relayer } from 'defender-relay-client';
import groupBy from 'lodash.groupby';
import chalk from 'chalk';
import fetch from 'node-fetch';
import { Relayer } from 'defender-relay-client';

import {
ContractsBlob,
Expand Down Expand Up @@ -75,11 +75,15 @@ export async function executeClaimerProfitablePrizeTxs(

// #2. Get data from v5-draw-results
const drawId = context.drawId.toString();
const claims = await fetchClaims(chainId, prizePool.address, drawId);
let claims = await fetchClaims(chainId, prizePool.address, drawId);

// #3. Cross-reference prizes claimed to flag if a claim has been claimed or not
claims = await flagClaimedRpc(readProvider, contracts, claims);

const unclaimedClaims = claims.filter((claim) => !claim.claimed);
const claimedClaims = claims.filter((claim) => claim.claimed);
if (claimedClaims.length === 0) {
console.log(chalk.dim(`No claimed prizes in subgraph for draw #${drawId}.`));
console.log(chalk.dim(`No claimed prizes for draw #${drawId}.`));
} else {
console.log(chalk.dim(`${claimedClaims.length} prizes already claimed for draw #${drawId}.`));
}
Expand All @@ -91,10 +95,10 @@ export async function executeClaimerProfitablePrizeTxs(
return;
}

// #3. Group claims by vault & tier
// #4. Group claims by vault & tier
const unclaimedClaimsGrouped = groupBy(unclaimedClaims, (item) => [item.vault, item.tier]);
console.log('unclaimedClaimsGrouped');
console.log(unclaimedClaimsGrouped);
// console.log('unclaimedClaimsGrouped');
// console.log(unclaimedClaimsGrouped);

for (let vaultTier of Object.entries(unclaimedClaimsGrouped)) {
const [key, value] = vaultTier;
Expand All @@ -105,7 +109,7 @@ export async function executeClaimerProfitablePrizeTxs(
printAsterisks();
console.log(chalk.blueBright(`Processing Vault: ${vault} Tier ${tier} ...`));

// #4. Decide if profitable or not
// #5. Decide if profitable or not
printAsterisks();
console.log(chalk.blue(`5a. Calculating # of profitable claims ...`));

Expand All @@ -123,7 +127,7 @@ export async function executeClaimerProfitablePrizeTxs(
);

// It's profitable if there is at least 1 claim to claim
// 5. Populate transaction
// #6. Populate transaction
if (claimPrizesParams.winners.length > 0) {
console.log(chalk.green('Claimer: Execute Claim Transaction'));
printSpacer();
Expand All @@ -137,15 +141,12 @@ export async function executeClaimerProfitablePrizeTxs(

console.log(chalk.greenBright.bold(`Flashbots (Private transaction) support:`, isPrivate));
console.log(chalk.greenBright.bold(`Sending transaction ...`));
let tx = await relayer.sendTransaction({
const tx = await relayer.sendTransaction({
isPrivate,
data: populatedTx.data,
to: populatedTx.to,
gasLimit: 8000000,
});
console.log(tx);
const updatedTx = await relayer.query(tx.transactionId);
console.log(updatedTx);

console.log(chalk.greenBright.bold('Transaction sent! ✔'));
console.log(chalk.blueBright.bold('Transaction hash:', tx.hash));
Expand Down Expand Up @@ -197,7 +198,6 @@ const calculateProfit = async (
`Native (Gas) Token ${NETWORK_NATIVE_TOKEN_INFO[chainId].symbol} Market Rate (USD):`,
gasTokenMarketRateUsd,
);
console.log(unclaimedClaims);

printSpacer();
const gasCost = await getGasCost(
Expand Down
22 changes: 11 additions & 11 deletions packages/library/src/drawBeaconHandleDrawStartAndComplete.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { PopulatedTransaction } from "@ethersproject/contracts";
import { getContract } from "@pooltogether/v5-utils-js";
import { PopulatedTransaction } from '@ethersproject/contracts';
import { getContract } from '@generationsoftware/pt-v5-utils-js';

import { ContractsBlob, ProviderOptions } from "./types";
// const debug = require("debug")("pt-autotask-lib");
import { ContractsBlob, ProviderOptions } from './types';
// const debug = require("debug")("pt-v5-autotask-lib");

export async function drawBeaconHandleDrawStartAndComplete(
contracts: ContractsBlob,
config: ProviderOptions
config: ProviderOptions,
): Promise<PopulatedTransaction | undefined> {
const { chainId, provider } = config;

const drawBeacon = getContract("DrawBeacon", chainId, provider, contracts);
const drawBeacon = getContract('DrawBeacon', chainId, provider, contracts);

if (!drawBeacon) {
throw new Error("DrawBeacon: Contract Unavailable");
throw new Error('DrawBeacon: Contract Unavailable');
}

const nextDrawId = await drawBeacon.getNextDrawId();
Expand All @@ -38,20 +38,20 @@ export async function drawBeaconHandleDrawStartAndComplete(
let transactionPopulated: PopulatedTransaction | undefined;

if (canStartDraw) {
console.log("DrawBeacon: Starting Draw");
console.log('DrawBeacon: Starting Draw');
transactionPopulated = await drawBeacon.populateTransaction.startDraw();
} else if (!canCompleteDraw) {
console.log(
`DrawBeacon: Draw ${nextDrawId} not ready to start.\nBeaconPeriodEndAt: ${beaconPeriodEndAt}`
`DrawBeacon: Draw ${nextDrawId} not ready to start.\nBeaconPeriodEndAt: ${beaconPeriodEndAt}`,
);
}

if (canCompleteDraw) {
console.log("DrawBeacon: Completing Draw");
console.log('DrawBeacon: Completing Draw');
transactionPopulated = await drawBeacon.populateTransaction.completeDraw();
} else if (!canStartDraw) {
console.log(
`DrawBeacon: Draw ${nextDrawId} not ready to complete.\nIsRngRequested: ${isRngRequested}\nIsRngCompleted: ${isRngCompleted}`
`DrawBeacon: Draw ${nextDrawId} not ready to complete.\nIsRngRequested: ${isRngRequested}\nIsRngCompleted: ${isRngCompleted}`,
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/library/src/drawReserve.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers, Contract, BigNumber } from 'ethers';
import { PopulatedTransaction } from '@ethersproject/contracts';
import { Provider } from '@ethersproject/providers';
import { getContract } from '@pooltogether/v5-utils-js';
import { getContract } from '@generationsoftware/pt-v5-utils-js';
import chalk from 'chalk';

import { ContractsBlob, Token, DrawReserveConfigParams, DrawReserveContext } from './types';
Expand Down
Loading

0 comments on commit 54d5c11

Please sign in to comment.