Skip to content

Commit

Permalink
Merge branch 'main' into qa-844-misaligned-bio
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers committed May 9, 2024
2 parents 8b9c430 + 8d2fe53 commit 81920c7
Show file tree
Hide file tree
Showing 152 changed files with 2,437 additions and 2,014 deletions.
6 changes: 6 additions & 0 deletions .changeset/spicy-elephants-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@audius/sdk': minor
'@audius/spl': major
---

Update to use PaymentRouterProgram in @audius/spl and enable track purchase in SDK
3 changes: 1 addition & 2 deletions .circleci/src/jobs/test-audius-cmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ steps:
cd ~/audius-protocol/packages/libs
. ~/.profile
audius-compose connect --nopass
# Disabled until it can be fixed
# ./scripts/check-generated-types.sh
./scripts/check-generated-types.sh
- run:
name: cleanup
no_output_timeout: 5m
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"DDEX_KEY": "49d5e13d355709b615b7cce7369174fb240b6b39",
"DDEX_SECRET": "2b2c2b90d9a489234ae629a5284de84fb0633306257f17667aaebf2345d92152",
"SESSION_SECRET": "something random",
"DDEX_ADMIN_ALLOWLIST": "127559427",
"DDEX_ADMIN_ALLOWLIST": "127559427,555164012",
"NODE_ENV": "stage"
}
}
16 changes: 13 additions & 3 deletions docs/docs/node-operator/setup/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ During installation there will be prompts for required environment variables. Th
Installing and managing Audius Nodes is (in most cases) a 3 step process.

1. Install `audius-ctl`
2. Edit the configuration file
3. Run your Audius Nodes
2. Confirm your
[ssh access and port configuration](/node-operator/setup/hardware-requirements#system-configuration)
3. Edit the configuration file
4. Run your Audius Nodes

---

Expand All @@ -76,7 +78,13 @@ Run the following command to install the controller utility, `audius-ctl`
curl -sSL https://install.audius.org | sh
```

> checkout the [code on GitHub](https://github.com/AudiusProject/audius-d)
:::tip Where to install audius-ctl

While it is recommended to install the controller utility on a separate computer, such as your
laptop, any machine can operate as a Controller. Check the
[Advanced Usage page](/node-operator/setup/advanced#audius-control-utility) for more information.

:::

---

Expand Down Expand Up @@ -179,6 +187,8 @@ Flags:
Use "audius-ctl [command] --help" for more information about a command.
```

> checkout the [code on GitHub](https://github.com/AudiusProject/audius-d)
---

## Migration Guide
Expand Down
2 changes: 1 addition & 1 deletion mediorum/.version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "0.6.97",
"version": "0.6.98",
"service": "content-node"
}
39 changes: 38 additions & 1 deletion packages/commands/src/purchase-content.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import chalk from 'chalk'
import { program } from 'commander'

import { initializeAudiusLibs } from './utils.mjs'
import { initializeAudiusLibs, initializeAudiusSdk } from './utils.mjs'
import { Utils } from '@audius/sdk'

program
.command('purchase-content')
Expand Down Expand Up @@ -79,3 +80,39 @@ program

process.exit(0)
})


program.command('purchase-track')
.description('Buys a track using USDC')
.argument('<id>', 'The track ID')
.option('-f, --from [from]', 'The account purchasing the content (handle)')
.option(
'-e, --extra-amount [amount]',
'Extra amount to pay in addition to the price (in dollars)'
, parseFloat)
.action(async (id, { from, extraAmount }) => {
const audiusLibs = await initializeAudiusLibs(from)
const userIdNumber = audiusLibs.userStateManager.getCurrentUserId()
const userId = Utils.encodeHashId(userIdNumber)
const trackId = Utils.encodeHashId(id)

// extract privkey and pubkey from hedgehog
// only works with accounts created via audius-cmd
const wallet = audiusLibs?.hedgehog?.getWallet()
const privKey = wallet?.getPrivateKeyString()
const pubKey = wallet?.getAddressString()

// init sdk with priv and pub keys as api keys and secret
// this enables writes via sdk
const audiusSdk = await initializeAudiusSdk({ apiKey: pubKey, apiSecret: privKey })

try {
console.log('Purchasing track...', { trackId, userId, extraAmount })
const response = await audiusSdk.tracks.purchase({ trackId, userId, extraAmount })
console.log(chalk.green('Successfully purchased track'))
console.log(chalk.yellow('Transaction Signature:'), response)
} catch (err) {
program.error(err)
}
process.exit(0)
})
20 changes: 10 additions & 10 deletions packages/commands/src/route-tokens-to-user-bank.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import chalk from 'chalk'
import { Option, program } from 'commander'

import { route } from '@audius/spl'
import { PaymentRouterProgram } from '@audius/spl'

import { initializeAudiusLibs } from './utils.mjs'

Expand Down Expand Up @@ -189,16 +189,16 @@ program
TOKEN_DECIMALS[mint]
)

const paymentRouterInstruction = await route(
paymentRouterTokenAccount,
paymentRouterPda,
const paymentRouterInstruction = await PaymentRouterProgram.route({
sender: paymentRouterTokenAccount,
senderOwner: paymentRouterPda,
paymentRouterPdaBump,
[userbankPublicKey], // recipients
[amount],
amount,
TOKEN_PROGRAM_ID,
paymentRouterPublicKey
)
recipients: [userbankPublicKey], // recipients
amounts: [amount],
totalAmount: amount,
tokenProgramId: TOKEN_PROGRAM_ID,
programId: paymentRouterPublicKey
})

transferTx.add(transferInstruction, paymentRouterInstruction)

Expand Down
44 changes: 24 additions & 20 deletions packages/commands/src/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {
Utils as AudiusUtils,
sdk as AudiusSdk,
libs as AudiusLibs,
developmentConfig,
DiscoveryNodeSelector,
EntityManager
SolanaRelay,
Configuration,
} from "@audius/sdk";
import { PublicKey } from "@solana/web3.js";

Expand Down Expand Up @@ -75,30 +75,34 @@ export const initializeAudiusLibs = async (handle) => {

let audiusSdk;
export const initializeAudiusSdk = async ({ apiKey = undefined, apiSecret = undefined } = {}) => {
const discoveryNodeSelector = new DiscoveryNodeSelector({
healthCheckThresholds: {
minVersion: developmentConfig.minVersion,
maxBlockDiff: developmentConfig.maxBlockDiff,
maxSlotDiffPlays: developmentConfig.maxSlotDiffPlays,
},
bootstrapServices: developmentConfig.discoveryNodes,
})
const entityManager = new EntityManager({
discoveryNodeSelector,
web3ProviderUrl: developmentConfig.web3ProviderUrl,
contractAddress: developmentConfig.entityManagerContractAddress,
identityServiceUrl: developmentConfig.identityServiceUrl,
useDiscoveryRelay: true,
})

const solanaRelay = new SolanaRelay(
new Configuration({
basePath: '/solana',
headers: {
'Content-Type': 'application/json'
},
middleware: [
{
pre: async (context) => {
const endpoint = 'http://audius-protocol-discovery-provider-1'
const url = `${endpoint}${context.url}`
return { url, init: context.init }
}
}
]
})
)

if (!audiusSdk) {
audiusSdk = AudiusSdk({
appName: "audius-cmd",
apiKey,
apiSecret,
environment: 'development',
services: {
discoveryNodeSelector,
entityManager
},
solanaRelay
}
});
}

Expand Down
3 changes: 1 addition & 2 deletions packages/common/src/schemas/upload/uploadFormSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,8 @@ export const createCollectionSchema = (collectionType: 'playlist' | 'album') =>
mood: MoodSchema,
tags: z.optional(z.string())
}),
is_unlisted: z.optional(z.boolean()),
is_album: z.literal(collectionType === 'album'),
is_private: z.optional(z.boolean()),
is_album: z.literal(collectionType === 'album'),
tracks: z.array(z.object({ metadata: CollectionTrackMetadataSchema })),
ddex_release_ids: z.optional(z.record(z.string()).nullable()),
artists: z.optional(z.array(DDEXResourceContributor).nullable()),
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/services/audius-backend/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ export const purchaseContentWithPaymentRouter = async (
purchaseAccess
}: PurchaseContentWithPaymentRouterArgs
) => {
const solanaWeb3Manager = (await audiusBackendInstance.getAudiusLibs())
const solanaWeb3Manager = (await audiusBackendInstance.getAudiusLibsTyped())
.solanaWeb3Manager!
const tx = await solanaWeb3Manager.purchaseContentWithPaymentRouter({
id,
Expand All @@ -436,7 +436,7 @@ export const purchaseContentWithPaymentRouter = async (
skipSendAndReturnTransaction: true,
purchaseAccess
})
return tx
return tx as Transaction
}

export const findAssociatedTokenAddress = async (
Expand Down
11 changes: 11 additions & 0 deletions packages/common/src/store/pages/audio-rewards/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ const slice = createSlice({
is_disbursed: true
}
}
const newlyDisbursedAmount = specifiers.reduce(
(acc, val) => acc + val.amount,
0
)
const previouslyDisbursedAmount =
state.userChallengesOverrides[challengeId]?.disbursed_amount ??
userChallenge.disbursed_amount
state.userChallengesOverrides[challengeId] = {
...state.userChallengesOverrides[challengeId],
disbursed_amount: previouslyDisbursedAmount + newlyDisbursedAmount
}
} else {
state.userChallengesOverrides[challengeId] = {
...state.userChallengesOverrides[challengeId],
Expand Down
4 changes: 2 additions & 2 deletions packages/ddex/ingester/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Crawls and parses new DDEX uploads.
### Local Dev
1. Make sure the DDEX dependencies are running: `audius-compose up --ddex-deps`
2. (Optional) See the webapp README to start that server and go through the OAuth flow with a staging user
3. Parse a file: `IS_DEV=true AWS_ENDPOINT=http://ingress:4566 DDEX_CHOREOGRAPHY=ERNBatched go run cmd/main.go ./e2e_test/fixtures/batch/fuga/20240305090456555 --wipe`
3. Parse a file: `IS_DEV=true AWS_ENDPOINT=http://ingress:4566 DDEX_CHOREOGRAPHY=ERNBatched go run cmd/main.go ./e2e_test/fixtures/batch/fuga/20240305090206405 --wipe`
4. Alternatively, run `IS_DEV=true AWS_ENDPOINT=http://ingress:4566 DDEX_CHOREOGRAPHY=ERNBatched air` to run the server with hot reloading. Then, run the webapp (see its README) to use its "Re-process All" button to test code changes against files you sync using the below instructions


Expand All @@ -19,4 +19,4 @@ Usage:
go run ./cmd/sync s3://ddex-prod-<provider>-raw/20240305090456555

aws s3 ls s3://ddex-prod-<provider>-raw/20240305090456555 --profile local
```
```
2 changes: 0 additions & 2 deletions packages/ddex/ingester/parser/ern38x.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,6 @@ func processSoundRecordingNode(sNode *xmlquery.Node) (recording *SoundRecording,
name := safeInnerText(contributorNode.SelectElement("PartyName/FullName"))
seqNo, seqNoErr := strconv.Atoi(contributorNode.SelectAttr("SequenceNumber"))
if seqNoErr != nil {
fmt.Printf("error parsing ResourceContributor %s's SequenceNumber: %v\n", name, seqNoErr)
seqNo = -1
}
contributor := common.ResourceContributor{
Expand All @@ -1168,7 +1167,6 @@ func processSoundRecordingNode(sNode *xmlquery.Node) (recording *SoundRecording,
name := safeInnerText(indirectContributorNode.SelectElement("PartyName/FullName"))
seqNo, seqNoErr := strconv.Atoi(indirectContributorNode.SelectAttr("SequenceNumber"))
if seqNoErr != nil {
fmt.Printf("error parsing IndirectResourceContributor %s's SequenceNumber: %v\n", name, seqNoErr)
seqNo = -1
}
contributor := common.ResourceContributor{
Expand Down
4 changes: 2 additions & 2 deletions packages/ddex/processor/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { pollS3 } from './src/s3poller'
import {
deleteRelease,
publishValidPendingReleases,
sdkService,
} from './src/publishRelease'
import { sync } from './src/s3sync'
import { startServer } from './src/server'
import { sleep } from './src/util'
import { releaseRepo } from './src/db'
import { createSdkService } from './src/sdk'

program
.name('ddexer')
Expand Down Expand Up @@ -45,7 +45,7 @@ program
.action(async (id) => {
// find release and delete it
const release = releaseRepo.get(id)
const sdk = (await sdkService).getSdk()
const sdk = (await createSdkService()).getSdk()
await deleteRelease(sdk, release!)
})

Expand Down
4 changes: 1 addition & 3 deletions packages/ddex/processor/src/publishRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import { DDEXContributor, DDEXRelease, DDEXResource } from './parseDelivery'
import { readAssetWithCaching } from './s3poller'
import { createSdkService } from './sdk'

export const sdkService = createSdkService()

export async function publishValidPendingReleases(opts?: {
republish: boolean
}) {
const rows = releaseRepo.all({ pendingPublish: true })
if (!rows.length) return

const sdk = (await sdkService).getSdk()
const sdk = (await createSdkService()).getSdk()

for (const row of rows) {
const parsed = row._parsed!
Expand Down
5 changes: 4 additions & 1 deletion packages/ddex/processor/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { prepareAlbumMetadata, prepareTrackMetadatas } from './publishRelease'
import { readAssetWithCaching } from './s3poller'
import { parseBool } from './util'
import { startUsersPoller } from './usersPoller'

const { NODE_ENV, DDEX_KEY, DDEX_URL, COOKIE_SECRET } = process.env
const COOKIE_NAME = 'audiusUser'
Expand All @@ -43,7 +44,7 @@ app.get('/', async (c) => {
: ''}
${me
? html`
<h4>Welcome back ${me.name}</h4>
<h4>Welcome back @${me.handle}</h4>
<a href="/auth/logout" role="button">log out</a>
`
: html` <a role="button" href="/auth">login</a> `}
Expand Down Expand Up @@ -547,4 +548,6 @@ export function startServer() {
fetch: app.fetch,
port,
})

startUsersPoller().catch(console.error)
}
29 changes: 29 additions & 0 deletions packages/ddex/processor/src/usersPoller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { userRepo } from './db'
import { createSdkService } from './sdk'

export async function startUsersPoller() {
const sdk = (await createSdkService()).getSdk()

// Periodic task to fetch user data and update names
setInterval(async () => {
try {
const users = userRepo.all()

for (const user of users) {
const { data: userResponse } = await sdk.users.getUser({ id: user.id })
if (!userResponse) {
throw new Error(`Error fetching user ${user.id} from sdk`)
}
if (userResponse.name !== user.name) {
userRepo.upsert({
...user,
name: userResponse.name
})
console.log(`Updated user ${user.id}'s name`)
}
}
} catch (error) {
console.error('Failed to update user names:', error)
}
}, 300000) // Runs every 5 min
}
2 changes: 1 addition & 1 deletion packages/discovery-provider/.version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "0.6.97",
"version": "0.6.98",
"service": "discovery-node"
}
Loading

0 comments on commit 81920c7

Please sign in to comment.