Skip to content

Commit

Permalink
accept the contractJsonUrl and subgraphUrl from cmd line args (instea…
Browse files Browse the repository at this point in the history
…d of the previous method of 's constants)
  • Loading branch information
chuckbergeron committed May 28, 2024
1 parent 1d6aca5 commit a75f433
Show file tree
Hide file tree
Showing 6 changed files with 1,070 additions and 1,123 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ Computes the previous draw's depositors with a non-zero balance for a PrizePool

JSON is in the format required by the [@GenerationSoftware/foundry-winner-calc](https://github.com/@GenerationSoftware/foundry-winner-calc) repo to quickly winners.

Simply pass a `chainId`, `prizePool` and `outDir` to compute and locally save the results.
Pass the `chainId`, `prizePool`, `outDir`, `contractJsonUrl` and `subgraphUrl` to compute and locally save the results.

```
USAGE
$ ptv5 utils vaultAccounts --chainId 1 --outDir ./temp --prizePool '0xdd4d117723C257CEe402285D3aCF218E9A8236E1'
$ ptv5 utils vaultAccounts --chainId 1 --outDir ./temp --prizePool '0xdd4d117723C257CEe402285D3aCF218E9A8236E1' --contractJsonUrl 'https://raw.githubusercontent.com/GenerationSoftware/pt-v5-testnet/.../contracts.json' --subgraphUrl 'https://api.studio.thegraph.com/query/...'
DESCRIPTION
Computes the previous draw's depositors with a non-zero balance for a PrizePool to a target output directory.
EXAMPLES
$ ptv5 utils vaultAccounts --chainId 1 --prizePool 0x0000000000000000000000000000000000000000 --outDir ./temp
$ ptv5 utils vaultAccounts --chainId 1 --prizePool 0x0000000000000000000000000000000000000000 --outDir ./temp --contractJsonUrl 'https://raw.githubusercontent.com/GenerationSoftware/pt-v5-testnet/.../contracts.json' --subgraphUrl 'https://api.studio.thegraph.com/query/...'
Running utils:vaultAccounts on chainId: 1
```

Expand Down Expand Up @@ -146,17 +146,17 @@ ptv5 utils concatWinners

Receives all of the winners by vault JSON files created by the [foundry-winner-calc](https://github.com/GenerationSoftware/foundry-winner-calc?tab=readme-ov-file) tool and ties them into one winners.json file. Therefore is dependent on `foundry-winner-calc` running prior to concatWinners being run.

Simply pass a `chainId`, `prizePool` and `outDir` to compute and locally save the results.
Pass the `chainId`, `prizePool`, `outDir`, `contractJsonUrl` and `subgraphUrl` to compute and locally save the results.

```
USAGE
$ ptv5 utils concatWinners --chainId 1 --outDir ./temp --prizePool '0xdd4d117723C257CEe402285D3aCF218E9A8236E1'
$ ptv5 utils concatWinners --chainId 1 --outDir ./temp --prizePool '0xdd4d117723C257CEe402285D3aCF218E9A8236E1' --contractJsonUrl 'https://raw.githubusercontent.com/GenerationSoftware/pt-v5-testnet/.../contracts.json' --subgraphUrl 'https://api.studio.thegraph.com/query/...'
DESCRIPTION
Ingests foundry-winner-calc output files and ties them into one winners.json file.
EXAMPLES
$ ptv5 utils concatWinners --chainId 1 --prizePool 0x0000000000000000000000000000000000000000 --outDir ./temp
$ ptv5 utils concatWinners --chainId 1 --prizePool 0x0000000000000000000000000000000000000000 --outDir ./temp --contractJsonUrl 'https://raw.githubusercontent.com/GenerationSoftware/pt-v5-testnet/.../contracts.json' --subgraphUrl 'https://api.studio.thegraph.com/query/...'
Running utils:concatWinners on chainId: 1
```

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"url": "https://github.com/generationsoftware"
},
"license": "MIT",
"version": "1.1.7",
"version": "1.2.0-beta.1",
"repository": "https://github.com/generationsoftware/pt-v5-cli",
"homepage": "https://github.com/generationsoftware/pt-v5-cli",
"bugs": "https://github.com/generationsoftware/pt-v5-cli/issues",
Expand Down Expand Up @@ -36,7 +36,7 @@
"@ethersproject/bignumber": "^5.5.0",
"@ethersproject/contracts": "^5.5.0",
"@ethersproject/providers": "^5.5.3",
"@generationsoftware/pt-v5-utils-js": "^1.1.11",
"@generationsoftware/pt-v5-utils-js": "1.2.0-beta.1",
"@oclif/core": "^3",
"@oclif/plugin-help": "^6",
"@oclif/plugin-plugins": "^4",
Expand Down
53 changes: 39 additions & 14 deletions src/commands/utils/concatWinners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class ConcatWinners extends Command {
static description =
"Ingests foundry-winner-calc output files and ties them into one winners.json file.";
static examples = [
`$ ptv5 utils concatWinners --chainId 1 --prizePool 0x0000000000000000000000000000000000000000 --outDir ./vaultAccounts
`$ ptv5 utils concatWinners --chainId 1 --prizePool 0x0000000000000000000000000000000000000000 --outDir ./vaultAccounts --contractJsonUrl 'https://raw.githubusercontent.com/GenerationSoftware/pt-v5-testnet/.../contracts.json' --subgraphUrl 'https://api.studio.thegraph.com/query/...'
Running utils:concatWinners on chainId: 1 for prizePool: 0x0 using latest drawID
`,
];
Expand All @@ -47,6 +47,16 @@ export default class ConcatWinners extends Command {
description: "Output Directory",
required: true,
}),
contractJsonUrl: Flags.string({
char: "j",
description: "JSON URL of Contracts",
required: true,
}),
subgraphUrl: Flags.string({
char: "s",
description: "URL of the Subgraph API",
required: true,
}),
};

static args = [];
Expand All @@ -55,11 +65,16 @@ export default class ConcatWinners extends Command {
public async catch(error: any): Promise<any> {
console.log(error, "_error vaultAccounts");
const { flags } = await this.parse(ConcatWinners);
const { chainId, prizePool, outDir } = flags;
const { chainId, prizePool, outDir, contractJsonUrl, subgraphUrl } = flags;

const readProvider = getProvider();

const prizePoolContract = await getPrizePoolByAddress(Number(chainId), prizePool, readProvider);
const prizePoolContract = await getPrizePoolByAddress(
Number(chainId),
contractJsonUrl,
prizePool,
readProvider
);

const drawId = await prizePoolContract?.getLastAwardedDrawId();

Expand All @@ -75,19 +90,29 @@ export default class ConcatWinners extends Command {

public async run(): Promise<void> {
const { flags } = await this.parse(ConcatWinners);
const { chainId, prizePool, outDir } = flags;
const { chainId, prizePool, outDir, contractJsonUrl, subgraphUrl } = flags;

console.log("");
console.log(
`Running "utils:concatWinners" on chainId: ${chainId} for prizePool: ${prizePool.toLowerCase()} using latest drawID`
);
console.log(`Running "utils:concatWinners"`);
console.log("");

const readProvider = getProvider();
const contracts = await downloadContractsBlob(Number(chainId));
const prizePoolContract = await getPrizePoolByAddress(Number(chainId), prizePool, readProvider);
const contracts = await downloadContractsBlob(contractJsonUrl);
const prizePoolContract = await getPrizePoolByAddress(
Number(chainId),
contractJsonUrl,
prizePool,
readProvider
);
const prizePoolInfo: PrizePoolInfo = await getPrizePoolInfo(readProvider, contracts);
const drawId = await prizePoolContract?.getLastAwardedDrawId();
console.log(`DrawID: #${drawId.toString()}`);

console.log(`chainId: ${chainId}`);
console.log(`prizePool: ${prizePool.toLowerCase()}`);
console.log(`drawId: #${drawId.toString()}`);
console.log(`contractJsonUrl: ${contractJsonUrl}`);
console.log(`subgraphUrl: ${subgraphUrl}`);
console.log(`outDir: ${outDir}`);

/* -------------------------------------------------- */
// Create Status File
Expand All @@ -96,7 +121,7 @@ export default class ConcatWinners extends Command {
writeToOutput(outDirWithSchema, "status", ConcatWinners.statusLoading);

const { prizeVaults, numAccounts } = await getAllPrizeVaultsAndAccountsWithBalance(
Number(chainId),
subgraphUrl,
prizePoolInfo
);
console.log();
Expand All @@ -109,7 +134,6 @@ export default class ConcatWinners extends Command {
/* -------------------------------------------------- */
writeCombinedWinnersToOutput(outDirWithSchema, prizeVaults);

console.log(`updateStatusSuccess`);
const statusSuccess = updateStatusSuccess(ConcatWinners.statusLoading.createdAt, {
numVaults: prizeVaults.length,
numTiers: prizePoolInfo.numTiers,
Expand All @@ -128,10 +152,11 @@ export default class ConcatWinners extends Command {

const getPrizePoolByAddress = async (
chainId: number,
contractJsonUrl: string,
prizePool: string,
readProvider: Provider
): Promise<Contract> => {
const contracts = await downloadContractsBlob(Number(chainId));
const contracts = await downloadContractsBlob(contractJsonUrl);

const prizePoolContractBlob = contracts.contracts.find(
(contract: any) =>
Expand Down Expand Up @@ -165,7 +190,7 @@ export function mapBigNumbersToStrings(bigNumbers: Record<string, BigNumber>) {
}

export function writeCombinedWinnersToOutput(outDirWithSchema: string, vaults: PrizeVault[]): void {
console.log("Writing depositors to output ...");
console.log("Writing combined winners to output ...");

let winnersJson: Record<string, Winner[]> = {};
for (const vault of Object.values(vaults)) {
Expand Down
51 changes: 38 additions & 13 deletions src/commands/utils/vaultAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class VaultAccounts extends Command {
static description =
"Outputs the previous draw's depositors with a non-zero balance for a PrizePool to a JSON file in a target directory.";
static examples = [
`$ ptv5 utils vaultAccounts --chainId 1 --prizePool 0x0000000000000000000000000000000000000000 --outDir ./depositors
`$ ptv5 utils vaultAccounts --chainId 1 --prizePool 0x0000000000000000000000000000000000000000 --outDir ./depositors --contractJsonUrl 'https://raw.githubusercontent.com/GenerationSoftware/pt-v5-testnet/.../contracts.json' --subgraphUrl 'https://api.studio.thegraph.com/query/...'
Running utils:vaultAccounts on chainId: 1 for prizePool: 0x0 using latest drawID
`,
];
Expand All @@ -45,6 +45,16 @@ export default class VaultAccounts extends Command {
description: "Output Directory",
required: true,
}),
contractJsonUrl: Flags.string({
char: "j",
description: "JSON URL of Contracts",
required: true,
}),
subgraphUrl: Flags.string({
char: "s",
description: "URL of the Subgraph API",
required: true,
}),
};

static args = [];
Expand All @@ -54,11 +64,16 @@ export default class VaultAccounts extends Command {
public async catch(error: any): Promise<any> {
console.log(error, "_error vaultAccounts");
const { flags } = await this.parse(VaultAccounts);
const { chainId, prizePool, outDir } = flags;
const { chainId, prizePool, outDir, contractJsonUrl, subgraphUrl } = flags;

const readProvider = getProvider();

const prizePoolContract = await getPrizePoolByAddress(Number(chainId), prizePool, readProvider);
const prizePoolContract = await getPrizePoolByAddress(
Number(chainId),
contractJsonUrl,
prizePool,
readProvider
);

const drawId = await prizePoolContract?.getLastAwardedDrawId();

Expand All @@ -74,17 +89,27 @@ export default class VaultAccounts extends Command {

public async run(): Promise<void> {
const { flags } = await this.parse(VaultAccounts);
const { chainId, prizePool, outDir } = flags;
const { chainId, prizePool, outDir, contractJsonUrl, subgraphUrl } = flags;

console.log("");
console.log(
`Running "utils:vaultAccounts" on chainId: ${chainId} for prizePool: ${prizePool.toLowerCase()} using latest drawID`
);
console.log(`Running "utils:vaultAccounts"`);
console.log("");

const readProvider = getProvider();
const prizePoolContract = await getPrizePoolByAddress(Number(chainId), prizePool, readProvider);
const prizePoolContract = await getPrizePoolByAddress(
Number(chainId),
contractJsonUrl,
prizePool,
readProvider
);
const drawId = await prizePoolContract?.getLastAwardedDrawId();
console.log(`DrawID: #${drawId.toString()}`);

console.log(`chainId: ${chainId}`);
console.log(`prizePool: ${prizePool.toLowerCase()}`);
console.log(`drawId: #${drawId.toString()}`);
console.log(`contractJsonUrl: ${contractJsonUrl}`);
console.log(`subgraphUrl: ${subgraphUrl}`);
console.log(`outDir: ${outDir}`);

/* -------------------------------------------------- */
// Create Status File
Expand All @@ -95,11 +120,11 @@ export default class VaultAccounts extends Command {
/* -------------------------------------------------- */
// Data Fetching && Compute
/* -------------------------------------------------- */
const contracts = await downloadContractsBlob(Number(chainId));
const contracts = await downloadContractsBlob(contractJsonUrl);
const prizePoolInfo: PrizePoolInfo = await getPrizePoolInfo(readProvider, contracts);

const { prizeVaults, numAccounts } = await getAllPrizeVaultsAndAccountsWithBalance(
Number(chainId),
subgraphUrl,
prizePoolInfo
);

Expand All @@ -108,7 +133,6 @@ export default class VaultAccounts extends Command {
/* -------------------------------------------------- */
writeDepositorsToOutput(outDirWithSchema, chainId, prizePool, prizeVaults);

console.log(`updateStatusSuccess`);
const statusSuccess = updateStatusSuccess(VaultAccounts.statusLoading.createdAt, {
numAccounts,
});
Expand All @@ -124,10 +148,11 @@ export default class VaultAccounts extends Command {

const getPrizePoolByAddress = async (
chainId: number,
contractJsonUrl: string,
prizePool: string,
readProvider: Provider
): Promise<Contract> => {
const contracts = await downloadContractsBlob(Number(chainId));
const contracts = await downloadContractsBlob(contractJsonUrl);

const prizePoolContractBlob = contracts.contracts.find(
(contract: any) =>
Expand Down
6 changes: 3 additions & 3 deletions src/lib/utils/getAllPrizeVaultsAndAccountsWithBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
} from "@generationsoftware/pt-v5-utils-js";

export const getAllPrizeVaultsAndAccountsWithBalance = async (
chainId: number,
subgraphUrl: string,
prizePoolInfo: PrizePoolInfo
): Promise<{ prizeVaults: PrizeVault[]; numAccounts: number }> => {
// #1. Collect all prizeVaults
console.log();
console.log(`Getting prize vaults from subgraph ...`);
let prizeVaults = await getSubgraphPrizeVaults(chainId);
let prizeVaults = await getSubgraphPrizeVaults(subgraphUrl);
if (prizeVaults.length === 0) {
throw new Error("Claimer: No prizeVaults found in subgraph");
}
Expand All @@ -34,7 +34,7 @@ export const getAllPrizeVaultsAndAccountsWithBalance = async (

// #5. Query and populate accounts for each vault
prizeVaults = await populateSubgraphPrizeVaultAccounts(
chainId,
subgraphUrl,
prizeVaults,
startTimestamp,
endTimestamp
Expand Down
Loading

0 comments on commit a75f433

Please sign in to comment.