@audius/sdk 0.0.35 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
- import solanaWeb3, { Connection, Keypair, PublicKey } from '@solana/web3.js';
2
+ import * as solanaWeb3 from '@solana/web3.js';
3
+ import { Connection, Keypair, PublicKey } from '@solana/web3.js';
3
4
  import type BN from 'bn.js';
4
5
  import splToken from '@solana/spl-token';
5
6
  import anchor, { Address, Idl, Program } from '@project-serum/anchor';
@@ -2,6 +2,7 @@ import type Web3 from 'web3';
2
2
  import type Wallet from 'ethereumjs-wallet';
3
3
  export declare type Web3Config = {
4
4
  registryAddress: string;
5
+ entityManagerAddress: string;
5
6
  useExternalWeb3: boolean;
6
7
  internalWeb3Config: {
7
8
  web3ProviderEndpoints: string[];
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@audius/sdk",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
4
4
  "audius": {
5
- "releaseSHA": "87ed35aa1374bdcf5632ef58ce55efbdd4031b03"
5
+ "releaseSHA": "6d1ca16dfb4944e5e5b83ee30e302fa4e6811da4"
6
6
  },
7
7
  "description": "",
8
8
  "main": "dist/index.cjs.js",
@@ -45,7 +45,7 @@
45
45
  "@improbable-eng/grpc-web-node-http-transport": "0.15.0",
46
46
  "@project-serum/anchor": "0.24.1",
47
47
  "@solana/spl-token": "0.1.8",
48
- "@solana/web3.js": "1.37.1",
48
+ "@solana/web3.js": "1.53.0",
49
49
  "abi-decoder": "2.4.0",
50
50
  "ajv": "6.12.2",
51
51
  "async-retry": "1.3.1",
@@ -98,6 +98,7 @@
98
98
  "@types/expect": "24.3.0",
99
99
  "@types/form-data": "^2.5.0",
100
100
  "@types/hashids": "2.0.1",
101
+ "@types/lodash": "4.14.149",
101
102
  "@types/mocha": "9.1.0",
102
103
  "@types/node-localstorage": "1.3.0",
103
104
  "@types/pify": "^5.0.1",
@@ -1,7 +1,6 @@
1
1
  import type { provider } from 'web3-core'
2
2
  import Web3 from './LibsWeb3'
3
3
  import { version } from './version'
4
- import type { SolanaWeb3Config } from './services/solana'
5
4
  import { Hedgehog, HedgehogConfig } from './services/hedgehog'
6
5
  import type { Hedgehog as HedgehogBase } from '@audius/hedgehog'
7
6
  import { CreatorNode, CreatorNodeConfig } from './services/creatorNode'
@@ -14,12 +13,19 @@ import { UserStateManager } from './userStateManager'
14
13
  import type { Logger, CaptchaConfig, Nullable } from './utils'
15
14
  import { Captcha, Utils } from './utils'
16
15
 
16
+ import { Keypair, PublicKey } from '@solana/web3.js'
17
+
17
18
  import { getPlatformLocalStorage, LocalStorage } from './utils/localStorage'
18
19
  import { Web3Config, Web3Manager } from './services/web3Manager'
19
20
  import { EthWeb3Config, EthWeb3Manager } from './services/ethWeb3Manager'
20
21
  import { Comstock } from './services/comstock'
21
22
  import { IdentityService } from './services/identity'
22
23
  import { EthContracts } from './services/ethContracts'
24
+ import {
25
+ SolanaWeb3Manager,
26
+ SolanaUtils,
27
+ SolanaWeb3Config
28
+ } from './services/solana'
23
29
  import { AudiusContracts } from './services/dataContracts'
24
30
  import { Account } from './api/Account'
25
31
  import { Users } from './api/Users'
@@ -42,6 +48,11 @@ type LibsHedgehogConfig = Omit<
42
48
  'identityService' | 'localStorage'
43
49
  >
44
50
 
51
+ type LibsSolanaWeb3Config = SolanaWeb3Config & {
52
+ // fee payer secret keys, if client wants to switch between different fee payers during relay
53
+ feePayerSecretKeys?: Uint8Array[]
54
+ }
55
+
45
56
  type LibsDiscoveryProviderConfig = Omit<
46
57
  DiscoveryProviderConfig,
47
58
  'userStateManager' | 'ethContracts' | 'web3Manager'
@@ -217,10 +228,51 @@ export class AudiusLibs {
217
228
 
218
229
  /**
219
230
  * Configures a solana web3
220
- * This is a stubbed version for native
221
231
  */
222
- static configSolanaWeb3() {
223
- return {}
232
+ static configSolanaWeb3({
233
+ solanaClusterEndpoint,
234
+ mintAddress,
235
+ solanaTokenAddress,
236
+ claimableTokenPDA,
237
+ feePayerAddress,
238
+ claimableTokenProgramAddress,
239
+ rewardsManagerProgramId,
240
+ rewardsManagerProgramPDA,
241
+ rewardsManagerTokenPDA,
242
+ useRelay,
243
+ feePayerSecretKeys,
244
+ confirmationTimeout,
245
+ audiusDataAdminStorageKeypairPublicKey,
246
+ audiusDataProgramId,
247
+ audiusDataIdl
248
+ }: LibsSolanaWeb3Config): SolanaWeb3Config {
249
+ if (audiusDataAdminStorageKeypairPublicKey instanceof String) {
250
+ audiusDataAdminStorageKeypairPublicKey = new PublicKey(
251
+ audiusDataAdminStorageKeypairPublicKey
252
+ )
253
+ }
254
+ if (audiusDataProgramId instanceof String) {
255
+ audiusDataProgramId = new PublicKey(audiusDataProgramId)
256
+ }
257
+ return {
258
+ solanaClusterEndpoint,
259
+ mintAddress,
260
+ solanaTokenAddress,
261
+ claimableTokenPDA,
262
+ feePayerAddress,
263
+ claimableTokenProgramAddress,
264
+ rewardsManagerProgramId,
265
+ rewardsManagerProgramPDA,
266
+ rewardsManagerTokenPDA,
267
+ useRelay,
268
+ feePayerKeypairs: feePayerSecretKeys?.map((key) =>
269
+ Keypair.fromSecretKey(key)
270
+ ),
271
+ confirmationTimeout,
272
+ audiusDataAdminStorageKeypairPublicKey,
273
+ audiusDataProgramId,
274
+ audiusDataIdl
275
+ }
224
276
  }
225
277
 
226
278
  /**
@@ -254,7 +306,7 @@ export class AudiusLibs {
254
306
  ethWeb3Manager: Nullable<EthWeb3Manager>
255
307
  ethContracts: Nullable<EthContracts>
256
308
  web3Manager: Nullable<Web3Manager>
257
- // solanaWeb3Manager: Nullable<SolanaWeb3Manager>
309
+ solanaWeb3Manager: Nullable<SolanaWeb3Manager>
258
310
  contracts: Nullable<AudiusContracts>
259
311
  creatorNode: Nullable<CreatorNode>
260
312
  captcha: Nullable<Captcha>
@@ -327,7 +379,7 @@ export class AudiusLibs {
327
379
  this.ethWeb3Manager = null
328
380
  this.ethContracts = null
329
381
  this.web3Manager = null
330
- // this.solanaWeb3Manager = null
382
+ this.solanaWeb3Manager = null
331
383
  this.contracts = null
332
384
  this.creatorNode = null
333
385
  this.captcha = null
@@ -404,6 +456,14 @@ export class AudiusLibs {
404
456
  this.identityService.setWeb3Manager(this.web3Manager)
405
457
  }
406
458
  }
459
+ if (this.solanaWeb3Config) {
460
+ this.solanaWeb3Manager = new SolanaWeb3Manager(
461
+ this.solanaWeb3Config,
462
+ this.identityService,
463
+ this.web3Manager
464
+ )
465
+ await this.solanaWeb3Manager.init()
466
+ }
407
467
 
408
468
  /** Contracts - Eth and Data Contracts */
409
469
  const contractsToInit = []
@@ -489,7 +549,7 @@ export class AudiusLibs {
489
549
  this.contracts,
490
550
  this.ethWeb3Manager,
491
551
  this.ethContracts,
492
- null as any,
552
+ this.solanaWeb3Manager,
493
553
  null as any,
494
554
  null as any,
495
555
  this.creatorNode,
@@ -515,5 +575,7 @@ export class AudiusLibs {
515
575
  }
516
576
  }
517
577
 
578
+ export { SolanaUtils }
579
+
518
580
  export { Utils } from './utils'
519
581
  export { SanityChecks } from './sanityChecks'
@@ -99,6 +99,7 @@ export class EntityManager extends Base {
99
99
  isAlbum,
100
100
  isPrivate,
101
101
  coverArt,
102
+ coverArtSizes,
102
103
  logger = console
103
104
  }: {
104
105
  playlistId: number
@@ -108,6 +109,7 @@ export class EntityManager extends Base {
108
109
  isAlbum: boolean
109
110
  isPrivate: boolean
110
111
  coverArt: string
112
+ coverArtSizes: string
111
113
  logger: Console
112
114
  }): Promise<PlaylistOperationResponse> {
113
115
  const responseValues: PlaylistOperationResponse =
@@ -123,10 +125,14 @@ export class EntityManager extends Base {
123
125
  const createAction = Action.CREATE
124
126
  const entityType = EntityType.PLAYLIST
125
127
  this.REQUIRES(Services.CREATOR_NODE)
126
- const updatedPlaylistImage = await this.creatorNode.uploadImage(
127
- coverArt,
128
- true // square
129
- )
128
+ let dirCID
129
+ if (coverArt) {
130
+ const updatedPlaylistImage = await this.creatorNode.uploadImage(
131
+ coverArt,
132
+ true // square
133
+ )
134
+ dirCID = updatedPlaylistImage.dirCID
135
+ }
130
136
  const web3 = this.web3Manager.getWeb3()
131
137
  const currentBlockNumber = await web3.eth.getBlockNumber()
132
138
  const currentBlock = await web3.eth.getBlock(currentBlockNumber)
@@ -134,12 +140,11 @@ export class EntityManager extends Base {
134
140
  track: trackId,
135
141
  time: currentBlock.timestamp as number
136
142
  }))
137
- const dirCID = updatedPlaylistImage.dirCID
138
143
  const metadata: PlaylistMetadata = {
139
144
  playlist_id: playlistId,
140
145
  playlist_contents: { track_ids: tracks },
141
146
  playlist_name: playlistName,
142
- playlist_image_sizes_multihash: dirCID,
147
+ playlist_image_sizes_multihash: dirCID ?? coverArtSizes,
143
148
  description,
144
149
  is_album: isAlbum,
145
150
  is_private: isPrivate
@@ -1,7 +1,8 @@
1
- import solanaWeb3, { Connection, Keypair, PublicKey } from '@solana/web3.js'
1
+ import * as solanaWeb3 from '@solana/web3.js'
2
+ import { Connection, Keypair, PublicKey } from '@solana/web3.js'
2
3
  import type BN from 'bn.js'
3
4
  import splToken from '@solana/spl-token'
4
- import anchor, { Address, Idl, Program } from '@project-serum/anchor'
5
+ import anchor, { Address, Idl, Program, Wallet } from '@project-serum/anchor'
5
6
  import { idl } from '@audius/anchor-audius-data'
6
7
 
7
8
  import { transferWAudioBalance } from './transfer'
@@ -166,7 +167,7 @@ export class SolanaWeb3Manager {
166
167
  } = this.solanaWeb3Config
167
168
 
168
169
  this.solanaClusterEndpoint = solanaClusterEndpoint
169
- this.connection = new solanaWeb3.Connection(this.solanaClusterEndpoint, {
170
+ this.connection = new Connection(this.solanaClusterEndpoint, {
170
171
  confirmTransactionInitialTimeout:
171
172
  confirmationTimeout || DEFAULT_CONNECTION_CONFIRMATION_TIMEOUT_MS
172
173
  })
@@ -230,14 +231,13 @@ export class SolanaWeb3Manager {
230
231
  this.audiusDataAdminStorageKeypairPublicKey &&
231
232
  this.audiusDataIdl
232
233
  ) {
233
- const connection = new solanaWeb3.Connection(
234
+ const connection = new Connection(
234
235
  this.solanaClusterEndpoint,
235
236
  anchor.AnchorProvider.defaultOptions()
236
237
  )
237
238
  const anchorProvider = new anchor.AnchorProvider(
238
239
  connection,
239
- // @ts-expect-error weirdness with 3rd party types
240
- solanaWeb3.Keypair.generate(),
240
+ Keypair.generate() as unknown as Wallet,
241
241
  anchor.AnchorProvider.defaultOptions()
242
242
  )
243
243
  this.anchorProgram = new anchor.Program(
@@ -3,6 +3,7 @@ import type Wallet from 'ethereumjs-wallet'
3
3
 
4
4
  export type Web3Config = {
5
5
  registryAddress: string
6
+ entityManagerAddress: string
6
7
  useExternalWeb3: boolean
7
8
  internalWeb3Config: {
8
9
  web3ProviderEndpoints: string[]
@@ -1,4 +1,5 @@
1
1
  import type { Hedgehog } from '@audius/hedgehog'
2
+ import { Keypair } from '@solana/web3.js'
2
3
  import type { EthContracts } from '../ethContracts'
3
4
  import type { ContractReceipt } from 'ethers'
4
5
  import type { EthWeb3Manager } from '../ethWeb3Manager'
@@ -269,10 +270,9 @@ export class Wormhole {
269
270
  const wAudioAmount = wAudioFromWeiAudio(amount)
270
271
  // Generate a solana keypair derived from the hedgehog private key
271
272
  // NOTE: The into to fromSeed is a 32 bytes Uint8Array
272
- const rootSolanaAccount =
273
- this.solanaWeb3Manager.solanaWeb3.Keypair.fromSeed(
274
- this.hedgehog.wallet?.getPrivateKey() as Uint8Array
275
- )
273
+ const rootSolanaAccount = Keypair.fromSeed(
274
+ this.hedgehog.wallet?.getPrivateKey() as Uint8Array
275
+ )
276
276
 
277
277
  const solanaAddress = rootSolanaAccount.publicKey.toString()
278
278
  logs.push(`Root Solana Account: ${solanaAddress}`)