Skip to content

Commit a75f433

Browse files
committed
accept the contractJsonUrl and subgraphUrl from cmd line args (instead of the previous method of 's constants)
1 parent 1d6aca5 commit a75f433

File tree

6 files changed

+1070
-1123
lines changed

6 files changed

+1070
-1123
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ Computes the previous draw's depositors with a non-zero balance for a PrizePool
7171

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

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

7676
```
7777
USAGE
78-
$ ptv5 utils vaultAccounts --chainId 1 --outDir ./temp --prizePool '0xdd4d117723C257CEe402285D3aCF218E9A8236E1'
78+
$ 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/...'
7979
8080
DESCRIPTION
8181
Computes the previous draw's depositors with a non-zero balance for a PrizePool to a target output directory.
8282
8383
EXAMPLES
84-
$ ptv5 utils vaultAccounts --chainId 1 --prizePool 0x0000000000000000000000000000000000000000 --outDir ./temp
84+
$ 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/...'
8585
Running utils:vaultAccounts on chainId: 1
8686
```
8787

@@ -146,17 +146,17 @@ ptv5 utils concatWinners
146146

147147
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.
148148

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

151151
```
152152
USAGE
153-
$ ptv5 utils concatWinners --chainId 1 --outDir ./temp --prizePool '0xdd4d117723C257CEe402285D3aCF218E9A8236E1'
153+
$ 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/...'
154154
155155
DESCRIPTION
156156
Ingests foundry-winner-calc output files and ties them into one winners.json file.
157157
158158
EXAMPLES
159-
$ ptv5 utils concatWinners --chainId 1 --prizePool 0x0000000000000000000000000000000000000000 --outDir ./temp
159+
$ 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/...'
160160
Running utils:concatWinners on chainId: 1
161161
```
162162

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"url": "https://github.com/generationsoftware"
77
},
88
"license": "MIT",
9-
"version": "1.1.7",
9+
"version": "1.2.0-beta.1",
1010
"repository": "https://github.com/generationsoftware/pt-v5-cli",
1111
"homepage": "https://github.com/generationsoftware/pt-v5-cli",
1212
"bugs": "https://github.com/generationsoftware/pt-v5-cli/issues",
@@ -36,7 +36,7 @@
3636
"@ethersproject/bignumber": "^5.5.0",
3737
"@ethersproject/contracts": "^5.5.0",
3838
"@ethersproject/providers": "^5.5.3",
39-
"@generationsoftware/pt-v5-utils-js": "^1.1.11",
39+
"@generationsoftware/pt-v5-utils-js": "1.2.0-beta.1",
4040
"@oclif/core": "^3",
4141
"@oclif/plugin-help": "^6",
4242
"@oclif/plugin-plugins": "^4",

src/commands/utils/concatWinners.ts

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default class ConcatWinners extends Command {
2626
static description =
2727
"Ingests foundry-winner-calc output files and ties them into one winners.json file.";
2828
static examples = [
29-
`$ ptv5 utils concatWinners --chainId 1 --prizePool 0x0000000000000000000000000000000000000000 --outDir ./vaultAccounts
29+
`$ 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/...'
3030
Running utils:concatWinners on chainId: 1 for prizePool: 0x0 using latest drawID
3131
`,
3232
];
@@ -47,6 +47,16 @@ export default class ConcatWinners extends Command {
4747
description: "Output Directory",
4848
required: true,
4949
}),
50+
contractJsonUrl: Flags.string({
51+
char: "j",
52+
description: "JSON URL of Contracts",
53+
required: true,
54+
}),
55+
subgraphUrl: Flags.string({
56+
char: "s",
57+
description: "URL of the Subgraph API",
58+
required: true,
59+
}),
5060
};
5161

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

6070
const readProvider = getProvider();
6171

62-
const prizePoolContract = await getPrizePoolByAddress(Number(chainId), prizePool, readProvider);
72+
const prizePoolContract = await getPrizePoolByAddress(
73+
Number(chainId),
74+
contractJsonUrl,
75+
prizePool,
76+
readProvider
77+
);
6378

6479
const drawId = await prizePoolContract?.getLastAwardedDrawId();
6580

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

7691
public async run(): Promise<void> {
7792
const { flags } = await this.parse(ConcatWinners);
78-
const { chainId, prizePool, outDir } = flags;
93+
const { chainId, prizePool, outDir, contractJsonUrl, subgraphUrl } = flags;
7994

8095
console.log("");
81-
console.log(
82-
`Running "utils:concatWinners" on chainId: ${chainId} for prizePool: ${prizePool.toLowerCase()} using latest drawID`
83-
);
96+
console.log(`Running "utils:concatWinners"`);
97+
console.log("");
8498

8599
const readProvider = getProvider();
86-
const contracts = await downloadContractsBlob(Number(chainId));
87-
const prizePoolContract = await getPrizePoolByAddress(Number(chainId), prizePool, readProvider);
100+
const contracts = await downloadContractsBlob(contractJsonUrl);
101+
const prizePoolContract = await getPrizePoolByAddress(
102+
Number(chainId),
103+
contractJsonUrl,
104+
prizePool,
105+
readProvider
106+
);
88107
const prizePoolInfo: PrizePoolInfo = await getPrizePoolInfo(readProvider, contracts);
89108
const drawId = await prizePoolContract?.getLastAwardedDrawId();
90-
console.log(`DrawID: #${drawId.toString()}`);
109+
110+
console.log(`chainId: ${chainId}`);
111+
console.log(`prizePool: ${prizePool.toLowerCase()}`);
112+
console.log(`drawId: #${drawId.toString()}`);
113+
console.log(`contractJsonUrl: ${contractJsonUrl}`);
114+
console.log(`subgraphUrl: ${subgraphUrl}`);
115+
console.log(`outDir: ${outDir}`);
91116

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

98123
const { prizeVaults, numAccounts } = await getAllPrizeVaultsAndAccountsWithBalance(
99-
Number(chainId),
124+
subgraphUrl,
100125
prizePoolInfo
101126
);
102127
console.log();
@@ -109,7 +134,6 @@ export default class ConcatWinners extends Command {
109134
/* -------------------------------------------------- */
110135
writeCombinedWinnersToOutput(outDirWithSchema, prizeVaults);
111136

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

129153
const getPrizePoolByAddress = async (
130154
chainId: number,
155+
contractJsonUrl: string,
131156
prizePool: string,
132157
readProvider: Provider
133158
): Promise<Contract> => {
134-
const contracts = await downloadContractsBlob(Number(chainId));
159+
const contracts = await downloadContractsBlob(contractJsonUrl);
135160

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

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

170195
let winnersJson: Record<string, Winner[]> = {};
171196
for (const vault of Object.values(vaults)) {

src/commands/utils/vaultAccounts.ts

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class VaultAccounts extends Command {
2424
static description =
2525
"Outputs the previous draw's depositors with a non-zero balance for a PrizePool to a JSON file in a target directory.";
2626
static examples = [
27-
`$ ptv5 utils vaultAccounts --chainId 1 --prizePool 0x0000000000000000000000000000000000000000 --outDir ./depositors
27+
`$ 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/...'
2828
Running utils:vaultAccounts on chainId: 1 for prizePool: 0x0 using latest drawID
2929
`,
3030
];
@@ -45,6 +45,16 @@ export default class VaultAccounts extends Command {
4545
description: "Output Directory",
4646
required: true,
4747
}),
48+
contractJsonUrl: Flags.string({
49+
char: "j",
50+
description: "JSON URL of Contracts",
51+
required: true,
52+
}),
53+
subgraphUrl: Flags.string({
54+
char: "s",
55+
description: "URL of the Subgraph API",
56+
required: true,
57+
}),
4858
};
4959

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

5969
const readProvider = getProvider();
6070

61-
const prizePoolContract = await getPrizePoolByAddress(Number(chainId), prizePool, readProvider);
71+
const prizePoolContract = await getPrizePoolByAddress(
72+
Number(chainId),
73+
contractJsonUrl,
74+
prizePool,
75+
readProvider
76+
);
6277

6378
const drawId = await prizePoolContract?.getLastAwardedDrawId();
6479

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

7590
public async run(): Promise<void> {
7691
const { flags } = await this.parse(VaultAccounts);
77-
const { chainId, prizePool, outDir } = flags;
92+
const { chainId, prizePool, outDir, contractJsonUrl, subgraphUrl } = flags;
7893

7994
console.log("");
80-
console.log(
81-
`Running "utils:vaultAccounts" on chainId: ${chainId} for prizePool: ${prizePool.toLowerCase()} using latest drawID`
82-
);
95+
console.log(`Running "utils:vaultAccounts"`);
96+
console.log("");
8397

8498
const readProvider = getProvider();
85-
const prizePoolContract = await getPrizePoolByAddress(Number(chainId), prizePool, readProvider);
99+
const prizePoolContract = await getPrizePoolByAddress(
100+
Number(chainId),
101+
contractJsonUrl,
102+
prizePool,
103+
readProvider
104+
);
86105
const drawId = await prizePoolContract?.getLastAwardedDrawId();
87-
console.log(`DrawID: #${drawId.toString()}`);
106+
107+
console.log(`chainId: ${chainId}`);
108+
console.log(`prizePool: ${prizePool.toLowerCase()}`);
109+
console.log(`drawId: #${drawId.toString()}`);
110+
console.log(`contractJsonUrl: ${contractJsonUrl}`);
111+
console.log(`subgraphUrl: ${subgraphUrl}`);
112+
console.log(`outDir: ${outDir}`);
88113

89114
/* -------------------------------------------------- */
90115
// Create Status File
@@ -95,11 +120,11 @@ export default class VaultAccounts extends Command {
95120
/* -------------------------------------------------- */
96121
// Data Fetching && Compute
97122
/* -------------------------------------------------- */
98-
const contracts = await downloadContractsBlob(Number(chainId));
123+
const contracts = await downloadContractsBlob(contractJsonUrl);
99124
const prizePoolInfo: PrizePoolInfo = await getPrizePoolInfo(readProvider, contracts);
100125

101126
const { prizeVaults, numAccounts } = await getAllPrizeVaultsAndAccountsWithBalance(
102-
Number(chainId),
127+
subgraphUrl,
103128
prizePoolInfo
104129
);
105130

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

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

125149
const getPrizePoolByAddress = async (
126150
chainId: number,
151+
contractJsonUrl: string,
127152
prizePool: string,
128153
readProvider: Provider
129154
): Promise<Contract> => {
130-
const contracts = await downloadContractsBlob(Number(chainId));
155+
const contracts = await downloadContractsBlob(contractJsonUrl);
131156

132157
const prizePoolContractBlob = contracts.contracts.find(
133158
(contract: any) =>

src/lib/utils/getAllPrizeVaultsAndAccountsWithBalance.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import {
66
} from "@generationsoftware/pt-v5-utils-js";
77

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

3535
// #5. Query and populate accounts for each vault
3636
prizeVaults = await populateSubgraphPrizeVaultAccounts(
37-
chainId,
37+
subgraphUrl,
3838
prizeVaults,
3939
startTimestamp,
4040
endTimestamp

0 commit comments

Comments
 (0)