diff --git a/.changeset/tough-ways-bow.md b/.changeset/tough-ways-bow.md new file mode 100644 index 00000000000..6bf8351f848 --- /dev/null +++ b/.changeset/tough-ways-bow.md @@ -0,0 +1,5 @@ +--- +"@audius/sdk": patch +--- + +Add alpha version of challengesApi.claimAllRewards diff --git a/dev-tools/compose/docker-compose.discovery.prod.yml b/dev-tools/compose/docker-compose.discovery.prod.yml index 599255b9f19..e2f5f1dd697 100644 --- a/dev-tools/compose/docker-compose.discovery.prod.yml +++ b/dev-tools/compose/docker-compose.discovery.prod.yml @@ -148,6 +148,8 @@ services: audius_delegate_owner_wallet: '0x73EB6d82CFB20bA669e9c178b718d770C49BB52f' audius_delegate_private_key: d09ba371c359f10f22ccda12fd26c598c7921bda3220c9942174562bc6a36fe8 + anti_abuse_wallet_pubkey: '0xF0D5BC18421fa04D0a2A2ef540ba5A9f04014BE3' + audius_discprov_dev_mode: 'true' audius_discprov_loglevel: 'debug' volumes: diff --git a/dev-tools/compose/nginx_ingress.conf b/dev-tools/compose/nginx_ingress.conf index 3e666b5aa7b..9285b0b4d44 100644 --- a/dev-tools/compose/nginx_ingress.conf +++ b/dev-tools/compose/nginx_ingress.conf @@ -75,9 +75,16 @@ server { location ~ ^/core(/.*)?$ { resolver 127.0.0.11 valid=30s; - proxy_pass http://audiusd-1:26659/core$1; + proxy_pass http://audiusd-1:26659/core$1$is_args$args; proxy_set_header Host $http_host; } + + location ~ ^/v1/rewards(/.*)?$ { + resolver 127.0.0.11 valid=30s; + proxy_pass http://host.docker.internal:1323/v1/rewards$1; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } } @@ -183,7 +190,7 @@ server { location ~ ^/core(/.*)?$ { resolver 127.0.0.11 valid=30s; - proxy_pass http://audiusd-2:26659/core$1; + proxy_pass http://audiusd-2:26659/core$1$is_args$args; proxy_set_header Host $http_host; } } @@ -210,7 +217,7 @@ server { location ~ ^/core(/.*)?$ { resolver 127.0.0.11 valid=30s; - proxy_pass http://audiusd-3:26659/core$1; + proxy_pass http://audiusd-3:26659/core$1$is_args$args; proxy_set_header Host $http_host; } } @@ -237,7 +244,7 @@ server { location ~ ^/core(/.*)?$ { resolver 127.0.0.11 valid=30s; - proxy_pass http://audiusd-4:26659/core$1; + proxy_pass http://audiusd-4:26659/core$1$is_args$args; proxy_set_header Host $http_host; } } diff --git a/dev-tools/startup/discovery-provider.sh b/dev-tools/startup/discovery-provider.sh index 826577907af..01d1eb604b7 100644 --- a/dev-tools/startup/discovery-provider.sh +++ b/dev-tools/startup/discovery-provider.sh @@ -1,3 +1,3 @@ #!/usr/bin/env sh # Create sender for current DN -../../node_modules/.bin/ts-node ./scripts/createSender.ts ${replica} & +../../node_modules/.bin/ts-node ./scripts/createSender.ts discovery-node ${replica} & diff --git a/packages/commands/src/index.ts b/packages/commands/src/index.ts index b06b8e2ae47..af2790d491d 100755 --- a/packages/commands/src/index.ts +++ b/packages/commands/src/index.ts @@ -8,6 +8,7 @@ import { managerCommand } from './manager/account-managers.js' import { authHeadersCommand } from './misc/auth-headers.js' import { claimRewardCommand, + claimRewardsCommand, rewardSpecifierCommand } from './misc/claim-reward.js' import { createUserBankCommand } from './misc/create-user-bank.js' @@ -32,6 +33,7 @@ async function main() { program.addCommand(managerCommand) program.addCommand(authHeadersCommand) program.addCommand(claimRewardCommand) + program.addCommand(claimRewardsCommand) program.addCommand(rewardSpecifierCommand) program.addCommand(createUserBankCommand) program.addCommand(mintCommand) diff --git a/packages/commands/src/misc/claim-reward.ts b/packages/commands/src/misc/claim-reward.ts index 76cfc466ec2..2e35abf2393 100644 --- a/packages/commands/src/misc/claim-reward.ts +++ b/packages/commands/src/misc/claim-reward.ts @@ -1,8 +1,8 @@ import chalk from 'chalk' -import { Command } from '@commander-js/extra-typings' +import { Command, Option } from '@commander-js/extra-typings' import { getCurrentUserId, initializeAudiusSdk } from '../utils.js' -import type { ChallengeId, GenerateSpecifierRequest } from '@audius/sdk' +import { ChallengeId, GenerateSpecifierRequest } from '@audius/sdk' export const claimRewardCommand = new Command('claim-reward') .description('Claim a challenge reward') @@ -37,6 +37,33 @@ export const claimRewardCommand = new Command('claim-reward') console.log(chalk.yellow.bold('Transaction Signature:'), res) }) +export const claimRewardsCommand = new Command('claim-rewards') + .description('Claim all challenge rewards') + .option('-f, --from ', 'The account to claim from') + .option( + '-u, --userId ', + 'The user ID to claim for (defaults to signed in user)' + ) + .addOption( + new Option( + '-c, --challengeId ', + 'The challenge ID to claim' + ).argParser((v) => ChallengeId[v as keyof typeof ChallengeId]) + ) + .option('-s, --specifier ', 'The specifier to claim') + .action(async ({ from, userId, challengeId, specifier }) => { + const audiusSdk = await initializeAudiusSdk({ handle: from }) + const currentUserId = await getCurrentUserId() + + const res = await audiusSdk.challenges.claimAllRewards({ + userId: userId === undefined ? currentUserId : userId, + challengeId, + specifier + }) + console.log(chalk.green('Successfully claimed reward')) + console.log(chalk.yellow.bold('Transaction Signatures:'), res) + }) + export const rewardSpecifierCommand = new Command('reward-specifier') .description('Get the specifier for a challenge') .argument('', 'The ID of the challenge') diff --git a/packages/discovery-provider/scripts/createSender.ts b/packages/discovery-provider/scripts/createSender.ts index 3e22ca4e9d1..801f352ce50 100644 --- a/packages/discovery-provider/scripts/createSender.ts +++ b/packages/discovery-provider/scripts/createSender.ts @@ -40,19 +40,31 @@ const rewardManagerProgramId = new PublicKey( process.env.SOLANA_REWARD_MANAGER_PUBLIC_KEY ) -const main = async (id: number) => { +const main = async (serviceType: string, id: number) => { const connection = new Connection( 'http://audius-protocol-solana-test-validator-1:8899' ) // Get senderEthAddress - const senderEthAddress = process.env[`DP${id}_DELEGATE_OWNER_ADDRESS`] + const senderAddressEnvKey = + serviceType === 'content-node' + ? `CN${id}_SP_OWNER_ADDRESS` + : serviceType === 'aao' + ? `AAO_WALLET_ADDRESS` + : `DP${id}_DELEGATE_OWNER_ADDRESS` + const senderPrivateKeyEnvKey = + serviceType === 'content-node' + ? `CN${id}_SP_OWNER_PRIVATE_KEY` + : serviceType === 'aao' + ? `AAO_WALLET_PRIVATE_KEY` + : `DP${id}_DELEGATE_OWNER_PRIVATE_KEY` + const senderEthAddress = process.env[senderAddressEnvKey] if (!senderEthAddress) { - throw new Error(`DP${id}_DELEGATE_OWNER_ADDRESS not set`) + throw new Error(`${senderAddressEnvKey} not set`) } - const senderEthPrivateKey = process.env[`DP${id}_DELEGATE_OWNER_PRIVATE_KEY`] + const senderEthPrivateKey = process.env[senderPrivateKeyEnvKey] if (!senderEthPrivateKey) { - throw new Error(`DP${id}_DELEGATE_OWNER_PRIVATE_KEY not set`) + throw new Error(`${senderPrivateKeyEnvKey} not set`) } // Derive authority @@ -99,4 +111,4 @@ const main = async (id: number) => { program.parse() -main(Number.parseInt(program.args[0])) +main(program.args[0], Number.parseInt(program.args[1])) diff --git a/packages/discovery-provider/src/challenges/challenges.dev.json b/packages/discovery-provider/src/challenges/challenges.dev.json index 65153233d08..57f58552e91 100644 --- a/packages/discovery-provider/src/challenges/challenges.dev.json +++ b/packages/discovery-provider/src/challenges/challenges.dev.json @@ -7,7 +7,7 @@ "step_count": 7, "starting_block": 0, "weekly_pool": 25000, - "cooldown_days": 7 + "cooldown_days": 0 }, { "id": "e", @@ -36,7 +36,7 @@ "starting_block": 0, "amount": 1, "weekly_pool": 25000, - "cooldown_days": 7 + "cooldown_days": 0 }, { "id": "rv", @@ -46,7 +46,7 @@ "starting_block": 0, "amount": 1, "weekly_pool": 25000, - "cooldown_days": 7 + "cooldown_days": 0 }, { "id": "rd", @@ -55,7 +55,7 @@ "starting_block": 0, "amount": 1, "weekly_pool": 25000, - "cooldown_days": 7 + "cooldown_days": 0 }, { "id": "v", @@ -72,7 +72,7 @@ "starting_block": 0, "amount": 1, "weekly_pool": 25000, - "cooldown_days": 7 + "cooldown_days": 0 }, { "id": "tt", @@ -105,7 +105,7 @@ "active": true, "starting_block": 0, "weekly_pool": 25000, - "cooldown_days": 7 + "cooldown_days": 0 }, { "id": "fp", @@ -114,7 +114,7 @@ "active": true, "starting_block": 0, "weekly_pool": 25000, - "cooldown_days": 7 + "cooldown_days": 0 }, { "id": "b", @@ -125,7 +125,7 @@ "step_count": 2147483647, "starting_block": 0, "weekly_pool": 25000, - "cooldown_days": 7 + "cooldown_days": 0 }, { "id": "s", @@ -136,7 +136,7 @@ "step_count": 2147483647, "starting_block": 0, "weekly_pool": 25000, - "cooldown_days": 7 + "cooldown_days": 0 }, { "id": "o", diff --git a/packages/sdk/src/sdk/api/challenges/ChallengesApi.ts b/packages/sdk/src/sdk/api/challenges/ChallengesApi.ts index a8a76900dea..1331d91b251 100644 --- a/packages/sdk/src/sdk/api/challenges/ChallengesApi.ts +++ b/packages/sdk/src/sdk/api/challenges/ChallengesApi.ts @@ -23,10 +23,13 @@ import type { UsersApi } from '../users/UsersApi' import { ChallengeId, + ClaimAllRewardsSchema, ClaimRewardsRequest, ClaimRewardsSchema, GenerateSpecifierRequest, - GenerateSpecifierSchema + GenerateSpecifierSchema, + type ClaimAllResponseBody, + type ClaimAllRewardsRequest } from './types' export class ChallengesApi extends GeneratedChallengesApi { @@ -328,4 +331,23 @@ export class ChallengesApi extends GeneratedChallengesApi { } return instructions } + + /** + * @hidden + * Claims all the undisbursed rewards by user ID, user ID + challenge ID, + * or challenge ID + specifier. + */ + public async claimAllRewards(request: ClaimAllRewardsRequest) { + const args = await parseParams( + 'claimAllRewards', + ClaimAllRewardsSchema + )(request) + const res = await this.request({ + path: '/rewards/claim', + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: args + }) + return (await res.json()) as ClaimAllResponseBody + } } diff --git a/packages/sdk/src/sdk/api/challenges/types.ts b/packages/sdk/src/sdk/api/challenges/types.ts index 68eaaa8ecd1..2f72b73e46f 100644 --- a/packages/sdk/src/sdk/api/challenges/types.ts +++ b/packages/sdk/src/sdk/api/challenges/types.ts @@ -109,3 +109,29 @@ export type AttestationTransactionSignature = { export type AAOErrorResponse = { aaoErrorCode: number } + +export const ClaimAllRewardsSchema = z + .object({ + userId: HashId, + challengeId: z.nativeEnum(ChallengeId).optional() + }) + .or( + z.object({ + challengeId: z.nativeEnum(ChallengeId), + specifier: z.string() + }) + ) + +export type ClaimAllRewardsRequest = z.input + +type ClaimResult = { + challengeId: string + specifier: string + amount: string + signatures: string[] + error?: string +} + +export type ClaimAllResponseBody = { + data: ClaimResult[] +}