@audius/sdk 0.0.0

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.
Files changed (278) hide show
  1. package/.eslintrc +38 -0
  2. package/.prettierrc.js +1 -0
  3. package/.python-version +1 -0
  4. package/Dockerfile +15 -0
  5. package/README.md +3 -0
  6. package/babel.config.js +3 -0
  7. package/data-contracts/ABIs/AdminUpgradeabilityProxy.json +132 -0
  8. package/data-contracts/ABIs/BaseAdminUpgradeabilityProxy.json +113 -0
  9. package/data-contracts/ABIs/BaseUpgradeabilityProxy.json +22 -0
  10. package/data-contracts/ABIs/DiscoveryProviderFactory.json +189 -0
  11. package/data-contracts/ABIs/DiscoveryProviderFactoryInterface.json +61 -0
  12. package/data-contracts/ABIs/DiscoveryProviderStorage.json +205 -0
  13. package/data-contracts/ABIs/DiscoveryProviderStorageInterface.json +65 -0
  14. package/data-contracts/ABIs/ECDSA.json +4 -0
  15. package/data-contracts/ABIs/IPLDBlacklistFactory.json +168 -0
  16. package/data-contracts/ABIs/Initializable.json +4 -0
  17. package/data-contracts/ABIs/Migrations.json +67 -0
  18. package/data-contracts/ABIs/OpenZeppelinUpgradesAddress.json +4 -0
  19. package/data-contracts/ABIs/Ownable.json +79 -0
  20. package/data-contracts/ABIs/PlaylistFactory.json +669 -0
  21. package/data-contracts/ABIs/PlaylistFactoryInterface.json +42 -0
  22. package/data-contracts/ABIs/PlaylistStorage.json +250 -0
  23. package/data-contracts/ABIs/PlaylistStorageInterface.json +129 -0
  24. package/data-contracts/ABIs/Proxy.json +10 -0
  25. package/data-contracts/ABIs/Registry.json +240 -0
  26. package/data-contracts/ABIs/RegistryContract.json +102 -0
  27. package/data-contracts/ABIs/RegistryContractInterface.json +28 -0
  28. package/data-contracts/ABIs/RegistryInterface.json +66 -0
  29. package/data-contracts/ABIs/SigningLogic.json +43 -0
  30. package/data-contracts/ABIs/SigningLogicInitializable.json +46 -0
  31. package/data-contracts/ABIs/SocialFeatureFactory.json +460 -0
  32. package/data-contracts/ABIs/SocialFeatureStorage.json +225 -0
  33. package/data-contracts/ABIs/SocialFeatureStorageInterface.json +123 -0
  34. package/data-contracts/ABIs/TestContract.json +135 -0
  35. package/data-contracts/ABIs/TestContractInterface.json +19 -0
  36. package/data-contracts/ABIs/TestContractWithStorage.json +165 -0
  37. package/data-contracts/ABIs/TestContractWithStorageInterface.json +24 -0
  38. package/data-contracts/ABIs/TestStorage.json +144 -0
  39. package/data-contracts/ABIs/TestStorageInterface.json +42 -0
  40. package/data-contracts/ABIs/TestUserReplicaSetManager.json +432 -0
  41. package/data-contracts/ABIs/TrackFactory.json +391 -0
  42. package/data-contracts/ABIs/TrackFactoryInterface.json +73 -0
  43. package/data-contracts/ABIs/TrackStorage.json +223 -0
  44. package/data-contracts/ABIs/TrackStorageInterface.json +121 -0
  45. package/data-contracts/ABIs/UpgradeabilityProxy.json +37 -0
  46. package/data-contracts/ABIs/UserFactory.json +657 -0
  47. package/data-contracts/ABIs/UserFactoryInterface.json +65 -0
  48. package/data-contracts/ABIs/UserLibraryFactory.json +334 -0
  49. package/data-contracts/ABIs/UserReplicaSetManager.json +418 -0
  50. package/data-contracts/ABIs/UserStorage.json +233 -0
  51. package/data-contracts/ABIs/UserStorageInterface.json +93 -0
  52. package/data-contracts/signatureSchemas.ts +1236 -0
  53. package/dist/core.d.ts +446 -0
  54. package/dist/core.js +769 -0
  55. package/dist/core.js.map +1 -0
  56. package/dist/index.d.ts +689 -0
  57. package/dist/index.js +72850 -0
  58. package/dist/index.js.map +1 -0
  59. package/eth-contracts/ABIs/Address.json +4 -0
  60. package/eth-contracts/ABIs/AudiusAdminUpgradeabilityProxy.json +105 -0
  61. package/eth-contracts/ABIs/AudiusClaimDistributor.json +4968 -0
  62. package/eth-contracts/ABIs/AudiusToken.json +724 -0
  63. package/eth-contracts/ABIs/BaseUpgradeabilityProxy.json +23 -0
  64. package/eth-contracts/ABIs/Checkpointing.json +4 -0
  65. package/eth-contracts/ABIs/ClaimsManager.json +539 -0
  66. package/eth-contracts/ABIs/Context.json +11 -0
  67. package/eth-contracts/ABIs/DelegateManager.json +989 -0
  68. package/eth-contracts/ABIs/DelegateManagerV2.json +1049 -0
  69. package/eth-contracts/ABIs/DelegateManagerV2Bad.json +1049 -0
  70. package/eth-contracts/ABIs/ERC20.json +252 -0
  71. package/eth-contracts/ABIs/ERC20Burnable.json +287 -0
  72. package/eth-contracts/ABIs/ERC20Detailed.json +270 -0
  73. package/eth-contracts/ABIs/ERC20Mintable.json +364 -0
  74. package/eth-contracts/ABIs/ERC20Pausable.json +397 -0
  75. package/eth-contracts/ABIs/EthRewardsManager.json +174 -0
  76. package/eth-contracts/ABIs/Governance.json +938 -0
  77. package/eth-contracts/ABIs/GovernanceUpgraded.json +953 -0
  78. package/eth-contracts/ABIs/GovernanceV2.json +938 -0
  79. package/eth-contracts/ABIs/IERC20.json +200 -0
  80. package/eth-contracts/ABIs/Initializable.json +4 -0
  81. package/eth-contracts/ABIs/InitializableV2.json +14 -0
  82. package/eth-contracts/ABIs/Migrations.json +71 -0
  83. package/eth-contracts/ABIs/MinterRole.json +91 -0
  84. package/eth-contracts/ABIs/MockAccount.json +62 -0
  85. package/eth-contracts/ABIs/MockDelegateManager.json +55 -0
  86. package/eth-contracts/ABIs/MockStakingCaller.json +259 -0
  87. package/eth-contracts/ABIs/MockWormhole.json +106 -0
  88. package/eth-contracts/ABIs/OpenZeppelinUpgradesAddress.json +4 -0
  89. package/eth-contracts/ABIs/Ownable.json +93 -0
  90. package/eth-contracts/ABIs/Pausable.json +150 -0
  91. package/eth-contracts/ABIs/PauserRole.json +91 -0
  92. package/eth-contracts/ABIs/Proxy.json +10 -0
  93. package/eth-contracts/ABIs/Registry.json +288 -0
  94. package/eth-contracts/ABIs/Roles.json +4 -0
  95. package/eth-contracts/ABIs/SafeERC20.json +4 -0
  96. package/eth-contracts/ABIs/SafeMath.json +4 -0
  97. package/eth-contracts/ABIs/ServiceProviderFactory.json +1153 -0
  98. package/eth-contracts/ABIs/ServiceTypeManager.json +337 -0
  99. package/eth-contracts/ABIs/Staking.json +555 -0
  100. package/eth-contracts/ABIs/StakingUpgraded.json +570 -0
  101. package/eth-contracts/ABIs/TestContract.json +44 -0
  102. package/eth-contracts/ABIs/TrustedNotifierManager.json +265 -0
  103. package/eth-contracts/ABIs/Uint256Helpers.json +4 -0
  104. package/eth-contracts/ABIs/UpgradeabilityProxy.json +40 -0
  105. package/eth-contracts/ABIs/Wormhole.json +45 -0
  106. package/eth-contracts/ABIs/WormholeClient.json +155 -0
  107. package/examples/file.mp3 +0 -0
  108. package/examples/initAudiusLibs.js +86 -0
  109. package/examples/initializeVersions.js +95 -0
  110. package/examples/pic.jpg +0 -0
  111. package/initScripts/configureLocalDiscProv.js +167 -0
  112. package/initScripts/helpers/claim.js +43 -0
  113. package/initScripts/helpers/distributeTokens.js +24 -0
  114. package/initScripts/helpers/spRegistration.js +138 -0
  115. package/initScripts/helpers/utils.js +34 -0
  116. package/initScripts/helpers/version.js +93 -0
  117. package/initScripts/local.js +617 -0
  118. package/initScripts/mainnet.js +131 -0
  119. package/initScripts/manageProdRelayerWallets.js +191 -0
  120. package/package.json +125 -0
  121. package/rollup.config.js +164 -0
  122. package/scripts/AudiusClaimDistributor.json +4968 -0
  123. package/scripts/Wormhole.json +155 -0
  124. package/scripts/addCIDToIpldBlacklist.js +124 -0
  125. package/scripts/circleci-test.sh +53 -0
  126. package/scripts/communityRewards/transferCommunityRewardsToSolana.js +222 -0
  127. package/scripts/ipfs.sh +58 -0
  128. package/scripts/migrate_contracts.sh +25 -0
  129. package/scripts/reset.sh +65 -0
  130. package/scripts/test.sh +77 -0
  131. package/src/api/account.js +670 -0
  132. package/src/api/base.js +122 -0
  133. package/src/api/file.js +168 -0
  134. package/src/api/playlist.js +328 -0
  135. package/src/api/rewards.d.ts +4 -0
  136. package/src/api/rewards.js +682 -0
  137. package/src/api/serviceProvider.js +154 -0
  138. package/src/api/track.js +604 -0
  139. package/src/api/user.js +888 -0
  140. package/src/api/user.test.js +172 -0
  141. package/src/constants.ts +7 -0
  142. package/src/core.ts +3 -0
  143. package/src/index.js +6 -0
  144. package/src/libs.d.ts +3 -0
  145. package/src/libs.js +619 -0
  146. package/src/sanityChecks/addSecondaries.js +40 -0
  147. package/src/sanityChecks/assignReplicaSetIfNecessary.js +10 -0
  148. package/src/sanityChecks/index.d.ts +9 -0
  149. package/src/sanityChecks/index.js +31 -0
  150. package/src/sanityChecks/isCreator.js +73 -0
  151. package/src/sanityChecks/needsRecoveryEmail.js +20 -0
  152. package/src/sanityChecks/rolloverNodes.js +74 -0
  153. package/src/sanityChecks/sanitizeNodes.js +24 -0
  154. package/src/sanityChecks/syncNodes.js +28 -0
  155. package/src/sdk/constants.ts +10 -0
  156. package/src/sdk/index.ts +1 -0
  157. package/src/sdk/oauth/Oauth.ts +265 -0
  158. package/src/sdk/oauth/index.ts +1 -0
  159. package/src/sdk/sdk.ts +102 -0
  160. package/src/service-selection/ServiceSelection.test.ts +320 -0
  161. package/src/service-selection/ServiceSelection.ts +460 -0
  162. package/src/service-selection/constants.ts +14 -0
  163. package/src/service-selection/index.ts +1 -0
  164. package/src/services/ABIDecoder/AudiusABIDecoder.ts +71 -0
  165. package/src/services/ABIDecoder/index.ts +1 -0
  166. package/src/services/comstock/Comstock.ts +39 -0
  167. package/src/services/comstock/index.ts +1 -0
  168. package/src/services/contracts/ContractClient.ts +227 -0
  169. package/src/services/contracts/GovernedContractClient.ts +53 -0
  170. package/src/services/contracts/ProviderSelection.ts +42 -0
  171. package/src/services/creatorNode/CreatorNode.ts +1065 -0
  172. package/src/services/creatorNode/CreatorNodeSelection.test.ts +997 -0
  173. package/src/services/creatorNode/CreatorNodeSelection.ts +488 -0
  174. package/src/services/creatorNode/constants.ts +10 -0
  175. package/src/services/creatorNode/index.ts +2 -0
  176. package/src/services/dataContracts/AudiusContracts.ts +234 -0
  177. package/src/services/dataContracts/IPLDBlacklistFactoryClient.ts +73 -0
  178. package/src/services/dataContracts/PlaylistFactoryClient.ts +370 -0
  179. package/src/services/dataContracts/RegistryClient.ts +95 -0
  180. package/src/services/dataContracts/SocialFeatureFactoryClient.ts +196 -0
  181. package/src/services/dataContracts/TrackFactoryClient.ts +131 -0
  182. package/src/services/dataContracts/UserFactoryClient.ts +351 -0
  183. package/src/services/dataContracts/UserLibraryFactoryClient.ts +115 -0
  184. package/src/services/dataContracts/UserReplicaSetManagerClient.ts +206 -0
  185. package/src/services/dataContracts/index.ts +1 -0
  186. package/src/services/discoveryProvider/DiscoveryProvider.ts +1168 -0
  187. package/src/services/discoveryProvider/DiscoveryProviderSelection.test.ts +536 -0
  188. package/src/services/discoveryProvider/DiscoveryProviderSelection.ts +383 -0
  189. package/src/services/discoveryProvider/constants.ts +13 -0
  190. package/src/services/discoveryProvider/index.ts +1 -0
  191. package/src/services/discoveryProvider/requests.ts +629 -0
  192. package/src/services/ethContracts/AudiusTokenClient.ts +163 -0
  193. package/src/services/ethContracts/ClaimDistributionClient.ts +45 -0
  194. package/src/services/ethContracts/ClaimsManagerClient.ts +102 -0
  195. package/src/services/ethContracts/DelegateManagerClient.ts +480 -0
  196. package/src/services/ethContracts/EthContracts.ts +359 -0
  197. package/src/services/ethContracts/EthRewardsManagerClient.ts +33 -0
  198. package/src/services/ethContracts/GovernanceClient.ts +451 -0
  199. package/src/services/ethContracts/RegistryClient.ts +33 -0
  200. package/src/services/ethContracts/ServiceProviderFactoryClient.ts +691 -0
  201. package/src/services/ethContracts/ServiceTypeManagerClient.ts +112 -0
  202. package/src/services/ethContracts/StakingProxyClient.ts +97 -0
  203. package/src/services/ethContracts/TrustedNotifierManagerClient.ts +101 -0
  204. package/src/services/ethContracts/WormholeClient.ts +97 -0
  205. package/src/services/ethContracts/index.ts +1 -0
  206. package/src/services/ethWeb3Manager/EthWeb3Manager.ts +239 -0
  207. package/src/services/ethWeb3Manager/index.ts +1 -0
  208. package/src/services/hedgehog/Hedgehog.ts +96 -0
  209. package/src/services/hedgehog/index.ts +1 -0
  210. package/src/services/identity/IdentityService.ts +551 -0
  211. package/src/services/identity/index.ts +1 -0
  212. package/src/services/identity/requests.ts +65 -0
  213. package/src/services/schemaValidator/SchemaValidator.ts +105 -0
  214. package/src/services/schemaValidator/index.ts +1 -0
  215. package/src/services/schemaValidator/schemas/trackSchema.json +267 -0
  216. package/src/services/schemaValidator/schemas/userSchema.json +230 -0
  217. package/src/services/solanaAudiusData/errors.ts +20 -0
  218. package/src/services/solanaAudiusData/index.ts +1189 -0
  219. package/src/services/solanaWeb3Manager/errors.js +101 -0
  220. package/src/services/solanaWeb3Manager/index.d.ts +46 -0
  221. package/src/services/solanaWeb3Manager/index.js +655 -0
  222. package/src/services/solanaWeb3Manager/padBNToUint8Array.ts +7 -0
  223. package/src/services/solanaWeb3Manager/rewards.js +941 -0
  224. package/src/services/solanaWeb3Manager/rewardsAttester.ts +1093 -0
  225. package/src/services/solanaWeb3Manager/tokenAccount.js +149 -0
  226. package/src/services/solanaWeb3Manager/transactionHandler.js +345 -0
  227. package/src/services/solanaWeb3Manager/transfer.js +272 -0
  228. package/src/services/solanaWeb3Manager/userBank.js +160 -0
  229. package/src/services/solanaWeb3Manager/utils.d.ts +31 -0
  230. package/src/services/solanaWeb3Manager/utils.js +163 -0
  231. package/src/services/solanaWeb3Manager/wAudio.js +28 -0
  232. package/src/services/solanaWeb3Manager/wAudio.test.js +30 -0
  233. package/src/services/web3Manager/Web3Config.ts +14 -0
  234. package/src/services/web3Manager/Web3Manager.ts +360 -0
  235. package/src/services/web3Manager/XMLHttpRequest.ts +11 -0
  236. package/src/services/web3Manager/index.ts +2 -0
  237. package/src/services/wormhole/index.js +424 -0
  238. package/src/types.ts +8 -0
  239. package/src/userStateManager.ts +53 -0
  240. package/src/utils/apiSigning.ts +51 -0
  241. package/src/utils/captcha.ts +97 -0
  242. package/src/utils/estimateGas.ts +64 -0
  243. package/src/utils/fileHasher.ts +278 -0
  244. package/src/utils/importContractABI.d.ts +9 -0
  245. package/src/utils/importContractABI.js +19 -0
  246. package/src/utils/index.ts +11 -0
  247. package/src/utils/multiProvider.ts +72 -0
  248. package/src/utils/network.test.ts +127 -0
  249. package/src/utils/network.ts +308 -0
  250. package/src/utils/promiseFight.test.ts +87 -0
  251. package/src/utils/promiseFight.ts +36 -0
  252. package/src/utils/signatures.ts +139 -0
  253. package/src/utils/types.ts +34 -0
  254. package/src/utils/utils.test.ts +36 -0
  255. package/src/utils/utils.ts +235 -0
  256. package/src/utils/uuid.ts +14 -0
  257. package/src/web3.d.ts +9 -0
  258. package/src/web3.js +8 -0
  259. package/tests/assets/static_image.png +0 -0
  260. package/tests/assets/static_text.txt +1 -0
  261. package/tests/audiusTokenClientTest.js +37 -0
  262. package/tests/creatorNodeTest.js +19 -0
  263. package/tests/fileHasherTest.js +125 -0
  264. package/tests/governanceTest.js +382 -0
  265. package/tests/helpers.js +105 -0
  266. package/tests/index.js +14 -0
  267. package/tests/playlistClientTest.js +157 -0
  268. package/tests/providerSelectionTest.js +241 -0
  269. package/tests/registryClientTest.js +19 -0
  270. package/tests/rewardsAttesterTest.js +373 -0
  271. package/tests/serviceTypeManagerClientTest.js +33 -0
  272. package/tests/socialFeatureClientTest.js +79 -0
  273. package/tests/stakingTest.js +302 -0
  274. package/tests/trackClientTest.js +86 -0
  275. package/tests/userClientTest.js +121 -0
  276. package/tsconfig.json +10 -0
  277. package/types/@audius-hedgehog/index.d.ts +39 -0
  278. package/types/abi-decoder/index.d.ts +41 -0
@@ -0,0 +1,1189 @@
1
+ import * as AudiusData from '@audius/anchor-audius-data'
2
+ import type { AudiusDataProgram } from '@audius/anchor-audius-data'
3
+ import anchor, { BN, Idl } from '@project-serum/anchor'
4
+ import type SolanaWeb3Manager from '../solanaWeb3Manager'
5
+ import type { Web3Manager } from '../web3Manager'
6
+ import { PublicKey, Keypair, SystemProgram, Transaction } from '@solana/web3.js'
7
+ import SolanaUtils from '../solanaWeb3Manager/utils'
8
+ import { audiusDataErrorMapping } from './errors'
9
+
10
+ type AnchorAudiusDataConfig = {
11
+ programId: string
12
+ adminAccount: string
13
+ }
14
+
15
+ type SeedAddress = {
16
+ bumpSeed: number
17
+ derivedAddress: anchor.web3.PublicKey
18
+ }
19
+
20
+ type OmitAndRequire<T, K extends keyof T, L extends keyof T> = Partial<
21
+ Omit<T, K>
22
+ > &
23
+ Required<Pick<T, L>>
24
+
25
+ /**
26
+ * SolanaAudiusData acts as the interface to solana audius data programs from a client.
27
+ * It wraps methods to create transactions.
28
+ */
29
+ export class SolanaAudiusData {
30
+ anchorAudiusDataConfig: AnchorAudiusDataConfig
31
+ solanaWeb3Manager: SolanaWeb3Manager
32
+ program!: AudiusDataProgram
33
+ programId!: PublicKey
34
+ adminAccount!: PublicKey
35
+ provider!: anchor.Provider
36
+ web3Manager: Web3Manager
37
+ // Exposes all other methods from @audius/anchor-audius-data for ad hoc use
38
+ AudiusData: any
39
+
40
+ /**
41
+ * @param {Object} anchorAudiusDataConfig The config object
42
+ * @param {string} anchorAudiusDataConfig.programId Program ID of the audius data program
43
+ * @param {string} anchorAudiusDataConfig.adminAccount Public Key of admin storage account
44
+ * @param {SolanaWeb3Manager} solanaWeb3Manager Solana web3 Manager
45
+ * @param {Web3Manager} web3Manager
46
+ */
47
+ constructor(
48
+ anchorAudiusDataConfig: AnchorAudiusDataConfig,
49
+ solanaWeb3Manager: SolanaWeb3Manager,
50
+ web3Manager: Web3Manager
51
+ ) {
52
+ this.anchorAudiusDataConfig = anchorAudiusDataConfig
53
+ this.solanaWeb3Manager = solanaWeb3Manager
54
+ this.web3Manager = web3Manager
55
+ this.AudiusData = AudiusData
56
+ }
57
+
58
+ async init() {
59
+ const { programId, adminAccount } = this.anchorAudiusDataConfig
60
+ this.programId = SolanaUtils.newPublicKeyNullable(programId)
61
+ this.adminAccount = SolanaUtils.newPublicKeyNullable(adminAccount)
62
+ this.provider = new anchor.AnchorProvider(
63
+ this.solanaWeb3Manager.connection,
64
+ // NOTE: Method requests type wallet, but because signtransaction is not used, keypair is fine
65
+ Keypair.generate() as any,
66
+ anchor.AnchorProvider.defaultOptions()
67
+ )
68
+ this.program = new anchor.Program(
69
+ AudiusData.idl as Idl,
70
+ this.programId,
71
+ this.provider
72
+ ) as any
73
+ }
74
+
75
+ // Setters
76
+ setAdminAccount(AdminAccount: PublicKey) {
77
+ this.adminAccount = AdminAccount
78
+ }
79
+
80
+ // ============================= HELPERS =============================
81
+
82
+ /**
83
+ * Validate that the program, provider and base variables were initted
84
+ * @returns {boolean} True if the class was initted
85
+ */
86
+ didInit() {
87
+ return Boolean(
88
+ this.programId &&
89
+ this.adminAccount &&
90
+ this.solanaWeb3Manager.feePayerKey &&
91
+ this.program
92
+ )
93
+ }
94
+
95
+ /**
96
+ * Encodes and derives the user account, bump seed, and base authority
97
+ */
98
+ async getUserIdSeed(userId: BN) {
99
+ // @ts-expect-error
100
+ const userIdSeed = userId.toArrayLike(Uint8Array, 'le', 4)
101
+ const {
102
+ baseAuthorityAccount,
103
+ bumpSeed,
104
+ derivedAddress: userAccount
105
+ } = await this.solanaWeb3Manager.findDerivedPair(
106
+ this.programId,
107
+ this.adminAccount,
108
+ userIdSeed
109
+ )
110
+ return {
111
+ userId,
112
+ userIdSeed,
113
+ userAccount,
114
+ bumpSeed,
115
+ baseAuthorityAccount
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Derives the user solana keypair using the user's eth private key
121
+ */
122
+ getUserKeyPair(): anchor.web3.Keypair {
123
+ return anchor.web3.Keypair.fromSeed(
124
+ this.web3Manager.ownerWallet.getPrivateKey()
125
+ )
126
+ }
127
+
128
+ /**
129
+ * Encodes and derives the content node account and bump seed
130
+ */
131
+ async getContentNodeSeedAddress(spId: number): Promise<SeedAddress> {
132
+ const enc = new TextEncoder() // always utf-8
133
+ const baseSpIdSeed = enc.encode('sp_id')
134
+ const spIdValue = new anchor.BN(spId).toArray('le', 2)
135
+ const { bumpSeed, derivedAddress } =
136
+ await this.solanaWeb3Manager.findDerivedPair(
137
+ this.programId,
138
+ this.adminAccount,
139
+ new Uint8Array([...baseSpIdSeed, ...spIdValue])
140
+ )
141
+ return {
142
+ bumpSeed,
143
+ derivedAddress
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Signs a transaction using the user's key pair
149
+ * NOTE: The blockhash and feepayer must be set when signing and passed along
150
+ * with the transaction for further signatures for consitency or the signature
151
+ * will be invalide
152
+ */
153
+ async signTransaction(
154
+ tx: anchor.web3.Transaction,
155
+ userKeyPair: anchor.web3.Keypair
156
+ ) {
157
+ const latestBlockHash =
158
+ await this.solanaWeb3Manager.connection.getLatestBlockhash('confirmed')
159
+
160
+ tx.recentBlockhash = latestBlockHash.blockhash
161
+ tx.feePayer = this.solanaWeb3Manager.feePayerKey
162
+
163
+ tx.partialSign(userKeyPair)
164
+ return tx
165
+ }
166
+
167
+ /**
168
+ * Submits a transaction via the solanaWeb3Manager transactionHandler passing along
169
+ * the signtures.
170
+ * This base method is used to send all transactions in this class
171
+ */
172
+ async sendTx(tx: Transaction) {
173
+ const signatures = tx.signatures
174
+ .filter((s) => s.signature && s.publicKey)
175
+ .map((s: any) => ({
176
+ publicKey: s.publicKey.toBase58(),
177
+ signature: s.signature
178
+ }))
179
+
180
+ const response =
181
+ await this.solanaWeb3Manager.transactionHandler.handleTransaction({
182
+ instructions: tx.instructions,
183
+ errorMapping: audiusDataErrorMapping,
184
+ feePayerOverride: this.solanaWeb3Manager.feePayerKey,
185
+ recentBlockhash: tx.recentBlockhash,
186
+ logger: console,
187
+ sendBlockhash: true,
188
+ signatures
189
+ })
190
+ return response
191
+ }
192
+
193
+ // ============================= PROGRAM METHODS =============================
194
+
195
+ /**
196
+ * Creates an admin account
197
+ * @memberof SolanaWeb3Manager
198
+ */
199
+ async initAdmin(
200
+ params: Omit<AudiusData.InitAdminParams, 'payer' | 'program'>
201
+ ) {
202
+ if (!this.program || !this.solanaWeb3Manager.feePayerKey) return
203
+ const tx = AudiusData.initAdmin({
204
+ payer: this.solanaWeb3Manager.feePayerKey,
205
+ program: this.program,
206
+ ...params
207
+ })
208
+ return await this.sendTx(tx)
209
+ }
210
+
211
+ /**
212
+ * Creates a user account to be claimed.
213
+ * NOTE: This transaction needs to be signed by the admin account
214
+ * @memberof SolanaWeb3Manager
215
+ */
216
+ async initUser(
217
+ params: OmitAndRequire<
218
+ AudiusData.InitUserParams,
219
+ 'program' | 'payer',
220
+ | 'userId'
221
+ | 'metadata'
222
+ | 'ethAddress'
223
+ | 'bumpSeed'
224
+ | 'userAccount'
225
+ | 'baseAuthorityAccount'
226
+ | 'cn1'
227
+ | 'cn2'
228
+ | 'cn3'
229
+ | 'replicaSet'
230
+ | 'replicaSetBumps'
231
+ | 'adminAuthorityPublicKey'
232
+ >
233
+ ) {
234
+ if (!this.didInit()) return
235
+ const tx = AudiusData.initUser({
236
+ payer: this.solanaWeb3Manager.feePayerKey,
237
+ program: this.program,
238
+ adminAccount: this.adminAccount,
239
+ ...params
240
+ })
241
+ return await this.sendTx(tx)
242
+ }
243
+
244
+ /**
245
+ * Claims a user account that is created via init user using secp
246
+ * @memberof SolanaWeb3Manager
247
+ */
248
+ async initUserSolPubkey(
249
+ params: Omit<
250
+ AudiusData.InitUserSolPubkeyParams,
251
+ 'program' | 'ethPrivateKey' | 'message'
252
+ > & {
253
+ userId: BN
254
+ }
255
+ ) {
256
+ if (!this.didInit()) return
257
+
258
+ const userSolKeypair = this.getUserKeyPair()
259
+ const { userAccount } = await this.getUserIdSeed(params.userId)
260
+ const tx = AudiusData.initUserSolPubkey({
261
+ program: this.program,
262
+ ethPrivateKey: this.web3Manager.ownerWallet.getPrivateKeyString(),
263
+ message: userSolKeypair.publicKey.toBytes(),
264
+ userAccount,
265
+ userAuthorityPublicKey: userSolKeypair.publicKey
266
+ })
267
+ return await this.sendTx(tx)
268
+ }
269
+
270
+ /**
271
+ * Creates a content node account
272
+ * NOTE: This transaction must be signed by the admin account
273
+ * @memberof SolanaWeb3Manager
274
+ */
275
+ async createContentNode(
276
+ params: OmitAndRequire<
277
+ AudiusData.CreateContentNodeParams,
278
+ 'program',
279
+ | 'spID'
280
+ | 'payer'
281
+ | 'adminAccount'
282
+ | 'adminAuthorityPublicKey'
283
+ | 'baseAuthorityAccount'
284
+ | 'spID'
285
+ | 'contentNodeAuthority'
286
+ | 'contentNodeAccount'
287
+ | 'ownerEthAddress'
288
+ >
289
+ ) {
290
+ if (!this.program) return
291
+ const tx = AudiusData.createContentNode({
292
+ program: this.program,
293
+ ...params
294
+ })
295
+ return await this.sendTx(tx)
296
+ }
297
+
298
+ /**
299
+ * Updates the user replica set in the user account
300
+ * NOTE: This transaction must be signed by a replica or the user's authority
301
+ * @memberof SolanaWeb3Manager
302
+ */
303
+ async updateUserReplicaSet(
304
+ params: Omit<AudiusData.UpdateUserReplicaSetParams, 'program' | 'payer'>
305
+ ) {
306
+ if (!this.program || !this.solanaWeb3Manager.feePayerKey) return
307
+ const tx = AudiusData.updateUserReplicaSet({
308
+ payer: this.solanaWeb3Manager.feePayerKey,
309
+ program: this.program,
310
+ ...params
311
+ })
312
+ return await this.sendTx(tx)
313
+ }
314
+
315
+ /**
316
+ * Create or update a content node using attestations from multiple content nodes
317
+ * @memberof SolanaWeb3Manager
318
+ */
319
+ async publicCreateOrUpdateContentNode(
320
+ params: Omit<
321
+ AudiusData.PublicCreateOrUpdateContentNodeParams,
322
+ 'program' | 'payer'
323
+ >
324
+ ) {
325
+ const tx = AudiusData.publicCreateOrUpdateContentNode({
326
+ program: this.program,
327
+ payer: this.solanaWeb3Manager.feePayerKey,
328
+ ...params
329
+ })
330
+ return await this.sendTx(tx)
331
+ }
332
+
333
+ /**
334
+ * Deletes a content node using attestations from multiple content nodes
335
+ * @memberof SolanaWeb3Manager
336
+ */
337
+ async publicDeleteContentNode(
338
+ params: Omit<AudiusData.PublicDeleteContentNodeParams, 'program' | 'payer'>
339
+ ) {
340
+ const tx = AudiusData.publicDeleteContentNode({
341
+ program: this.program,
342
+ payer: this.solanaWeb3Manager.feePayerKey,
343
+ ...params
344
+ })
345
+ return await this.sendTx(tx)
346
+ }
347
+
348
+ /**
349
+ * Creates a user account
350
+ * NOTE: This method can only we called after the admin account is write enabled false
351
+ * @memberof SolanaWeb3Manager
352
+ */
353
+ async createUser(
354
+ params: OmitAndRequire<
355
+ AudiusData.CreateUserParams,
356
+ 'program' | 'payer',
357
+ 'userId' | 'metadata'
358
+ > & {
359
+ cn1SpId: number
360
+ cn2SpId: number
361
+ cn3SpId: number
362
+ }
363
+ ) {
364
+ if (!this.didInit()) return
365
+
366
+ const ethAccount = {
367
+ privateKey: this.web3Manager.ownerWallet.getPrivateKeyString(),
368
+ address: this.web3Manager.ownerWallet.getAddressString()
369
+ }
370
+
371
+ const userSolKeypair = this.getUserKeyPair()
372
+ const { userAccount, bumpSeed, baseAuthorityAccount } =
373
+ await this.getUserIdSeed(params.userId)
374
+
375
+ const spSeedAddresses = await Promise.all(
376
+ [params.cn1SpId, params.cn2SpId, params.cn3SpId].map(
377
+ async (id) => await this.getContentNodeSeedAddress(id)
378
+ )
379
+ )
380
+
381
+ const tx = AudiusData.createUser({
382
+ program: this.program,
383
+ payer: this.solanaWeb3Manager.feePayerKey,
384
+ adminAccount: this.adminAccount,
385
+ baseAuthorityAccount,
386
+ ethAccount: ethAccount as any,
387
+ userId: params.userId,
388
+ bumpSeed,
389
+ userAccount,
390
+ userAuthorityPublicKey: userSolKeypair.publicKey,
391
+ message: userSolKeypair.publicKey.toBytes(),
392
+ replicaSet: [params.cn1SpId, params.cn2SpId, params.cn3SpId],
393
+ replicaSetBumps: spSeedAddresses.map(({ bumpSeed }) => bumpSeed),
394
+ cn1: (spSeedAddresses[0] as SeedAddress).derivedAddress,
395
+ cn2: (spSeedAddresses[1] as SeedAddress).derivedAddress,
396
+ cn3: (spSeedAddresses[2] as SeedAddress).derivedAddress,
397
+ metadata: params.metadata
398
+ })
399
+ return await this.sendTx(tx)
400
+ }
401
+
402
+ /**
403
+ * Updates a user account
404
+ * @memberof SolanaWeb3Manager
405
+ */
406
+ async updateUser(
407
+ params: OmitAndRequire<
408
+ AudiusData.UpdateUserParams,
409
+ 'program',
410
+ 'metadata'
411
+ > & { userId: anchor.BN }
412
+ ) {
413
+ if (!this.didInit()) return
414
+
415
+ const { userAccount } = await this.getUserIdSeed(params.userId)
416
+ const userSolKeypair = this.getUserKeyPair()
417
+ const tx = AudiusData.updateUser({
418
+ program: this.program,
419
+ userAccount,
420
+ userAuthorityPublicKey: userSolKeypair.publicKey,
421
+ userAuthorityDelegate: SystemProgram.programId,
422
+ authorityDelegationStatusAccount: SystemProgram.programId,
423
+ metadata: params.metadata
424
+ })
425
+ await this.signTransaction(tx, userSolKeypair)
426
+ return await this.sendTx(tx)
427
+ }
428
+
429
+ /**
430
+ * Updates the admin account, used for write enabled
431
+ * @memberof SolanaWeb3Manager
432
+ */
433
+ async updateAdmin(params: Omit<AudiusData.UpdateAdminParams, 'program'>) {
434
+ if (
435
+ !this.program ||
436
+ !this.solanaWeb3Manager.feePayerKey ||
437
+ !this.adminAccount
438
+ )
439
+ return
440
+
441
+ const tx = AudiusData.updateAdmin({
442
+ program: this.program,
443
+ ...params
444
+ })
445
+ return await this.sendTx(tx)
446
+ }
447
+
448
+ async initAuthorityDelegationStatus(
449
+ params: Omit<
450
+ AudiusData.InitAuthorityDelegationStatusParams,
451
+ 'program' | 'payer'
452
+ >
453
+ ) {
454
+ const tx = AudiusData.initAuthorityDelegationStatus({
455
+ program: this.program,
456
+ payer: this.solanaWeb3Manager.feePayerKey,
457
+ ...params
458
+ })
459
+ return await this.sendTx(tx)
460
+ }
461
+
462
+ async revokeAuthorityDelegation(
463
+ params: Omit<
464
+ AudiusData.RevokeAuthorityDelegationParams,
465
+ 'program' | 'payer'
466
+ >
467
+ ) {
468
+ const tx = AudiusData.revokeAuthorityDelegation({
469
+ program: this.program,
470
+ payer: this.solanaWeb3Manager.feePayerKey,
471
+ ...params
472
+ })
473
+ return await this.sendTx(tx)
474
+ }
475
+
476
+ async addUserAuthorityDelegate(
477
+ params: Omit<AudiusData.AddUserAuthorityDelegateParams, 'program' | 'payer'>
478
+ ) {
479
+ const tx = AudiusData.addUserAuthorityDelegate({
480
+ program: this.program,
481
+ payer: this.solanaWeb3Manager.feePayerKey,
482
+ ...params
483
+ })
484
+ return await this.sendTx(tx)
485
+ }
486
+
487
+ async removeUserAuthorityDelegate(
488
+ params: Omit<
489
+ AudiusData.RemoveUserAuthorityDelegateParams,
490
+ 'program' | 'payer'
491
+ >
492
+ ) {
493
+ const tx = AudiusData.removeUserAuthorityDelegate({
494
+ program: this.program,
495
+ payer: this.solanaWeb3Manager.feePayerKey,
496
+ ...params
497
+ })
498
+ return await this.sendTx(tx)
499
+ }
500
+
501
+ /**
502
+ * Updates a user to be verified
503
+ * NOTE: This tx must be signed by the admin verifier
504
+ * @memberof SolanaWeb3Manager
505
+ */
506
+ async updateIsVerified(
507
+ params: OmitAndRequire<
508
+ AudiusData.UpdateIsVerifiedParams,
509
+ 'program' | 'verifierPublicKey',
510
+ 'userId'
511
+ > & {
512
+ verifierKeyPair: anchor.web3.Keypair
513
+ }
514
+ ) {
515
+ if (!this.didInit()) return
516
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
517
+ await this.getUserIdSeed(params.userId)
518
+
519
+ const tx = AudiusData.updateIsVerified({
520
+ program: this.program,
521
+ adminAccount: this.adminAccount,
522
+ bumpSeed,
523
+ baseAuthorityAccount,
524
+ userAccount,
525
+ verifierPublicKey: params.verifierKeyPair.publicKey,
526
+ ...params
527
+ })
528
+ await this.signTransaction(tx, params.verifierKeyPair)
529
+ return await this.sendTx(tx)
530
+ }
531
+
532
+ // ============================= MANAGE ENTITY =============================
533
+
534
+ /**
535
+ * Creates a track
536
+ *
537
+ * @return {Promise<any>}
538
+ * @memberof SolanaWeb3Manager
539
+ */
540
+ async createTrack(
541
+ params: OmitAndRequire<
542
+ AudiusData.CreateEntityParams,
543
+ 'program',
544
+ 'id' | 'userId' | 'metadata'
545
+ >
546
+ ) {
547
+ if (!this.didInit()) return
548
+
549
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
550
+ await this.getUserIdSeed(params.userId)
551
+
552
+ const userSolKeypair = this.getUserKeyPair()
553
+ const tx = AudiusData.createTrack({
554
+ program: this.program,
555
+ adminAccount: this.adminAccount,
556
+ baseAuthorityAccount,
557
+ bumpSeed,
558
+ userAccount,
559
+ userAuthorityPublicKey: userSolKeypair.publicKey,
560
+ userAuthorityDelegateAccount: SystemProgram.programId,
561
+ authorityDelegationStatusAccount: SystemProgram.programId,
562
+ userId: params.userId,
563
+ id: params.id,
564
+ metadata: params.metadata
565
+ })
566
+ await this.signTransaction(tx, userSolKeypair)
567
+ return await this.sendTx(tx)
568
+ }
569
+
570
+ /**
571
+ * Updates a track
572
+ *
573
+ * @return {Promise<any>}
574
+ * @memberof SolanaWeb3Manager
575
+ */
576
+ async updateTrack(
577
+ params: OmitAndRequire<
578
+ AudiusData.UpdateEntityParams,
579
+ 'program',
580
+ 'id' | 'userId' | 'metadata'
581
+ >
582
+ ) {
583
+ if (!this.didInit()) return
584
+
585
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
586
+ await this.getUserIdSeed(params.userId)
587
+
588
+ const userSolKeypair = this.getUserKeyPair()
589
+
590
+ const tx = AudiusData.updateTrack({
591
+ program: this.program,
592
+ adminAccount: this.adminAccount,
593
+ baseAuthorityAccount,
594
+ bumpSeed,
595
+ userAccount,
596
+ userAuthorityPublicKey: userSolKeypair.publicKey,
597
+ userAuthorityDelegateAccount: SystemProgram.programId,
598
+ authorityDelegationStatusAccount: SystemProgram.programId,
599
+ userId: params.userId,
600
+ id: params.id,
601
+ metadata: params.metadata
602
+ })
603
+ await this.signTransaction(tx, userSolKeypair)
604
+ return await this.sendTx(tx)
605
+ }
606
+
607
+ /**
608
+ * Deletes a track
609
+ *
610
+ * @return {Promise<any>}
611
+ * @memberof SolanaWeb3Manager
612
+ */
613
+ async deleteTrack(
614
+ params: OmitAndRequire<
615
+ AudiusData.DeleteEntityParams,
616
+ 'program',
617
+ 'id' | 'userId'
618
+ >
619
+ ) {
620
+ if (!this.didInit()) return
621
+
622
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
623
+ await this.getUserIdSeed(params.userId)
624
+
625
+ const userSolKeypair = this.getUserKeyPair()
626
+ const tx = AudiusData.deleteTrack({
627
+ program: this.program,
628
+ adminAccount: this.adminAccount,
629
+ baseAuthorityAccount,
630
+ bumpSeed,
631
+ userAccount,
632
+ userAuthorityPublicKey: userSolKeypair.publicKey,
633
+ userAuthorityDelegateAccount: SystemProgram.programId,
634
+ authorityDelegationStatusAccount: SystemProgram.programId,
635
+ userId: params.userId,
636
+ id: params.id
637
+ })
638
+ await this.signTransaction(tx, userSolKeypair)
639
+ return await this.sendTx(tx)
640
+ }
641
+
642
+ /**
643
+ * Creates a solana transaction for createPlaylist
644
+ *
645
+ * @return {Promise<any>}
646
+ * @memberof SolanaWeb3Manager
647
+ */
648
+ async createPlaylist(
649
+ params: OmitAndRequire<
650
+ AudiusData.CreateEntityParams,
651
+ 'program',
652
+ 'id' | 'userId' | 'metadata'
653
+ >
654
+ ) {
655
+ if (!this.didInit()) return
656
+
657
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
658
+ await this.getUserIdSeed(params.userId)
659
+
660
+ const userSolKeypair = this.getUserKeyPair()
661
+ const tx = AudiusData.createPlaylist({
662
+ program: this.program,
663
+ adminAccount: this.adminAccount,
664
+ baseAuthorityAccount,
665
+ bumpSeed,
666
+ userAccount,
667
+ userAuthorityPublicKey: userSolKeypair.publicKey,
668
+ userAuthorityDelegateAccount: SystemProgram.programId,
669
+ authorityDelegationStatusAccount: SystemProgram.programId,
670
+ userId: params.userId,
671
+ id: params.id,
672
+ metadata: params.metadata
673
+ })
674
+ await this.signTransaction(tx, userSolKeypair)
675
+ return await this.sendTx(tx)
676
+ }
677
+
678
+ /**
679
+ * Creates a solana transaction for updatePlaylist
680
+ *
681
+ * @return {Promise<any>}
682
+ * @memberof SolanaWeb3Manager
683
+ */
684
+ async updatePlaylist(
685
+ params: OmitAndRequire<
686
+ AudiusData.UpdateEntityParams,
687
+ 'program',
688
+ 'id' | 'userId' | 'metadata'
689
+ >
690
+ ) {
691
+ if (!this.didInit()) return
692
+
693
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
694
+ await this.getUserIdSeed(params.userId)
695
+
696
+ const userSolKeypair = this.getUserKeyPair()
697
+ const tx = AudiusData.updatePlaylist({
698
+ program: this.program,
699
+ adminAccount: this.adminAccount,
700
+ baseAuthorityAccount,
701
+ bumpSeed,
702
+ userAccount,
703
+ userAuthorityPublicKey: userSolKeypair.publicKey,
704
+ userAuthorityDelegateAccount: SystemProgram.programId,
705
+ authorityDelegationStatusAccount: SystemProgram.programId,
706
+ userId: params.userId,
707
+ id: params.id,
708
+ metadata: params.metadata
709
+ })
710
+ await this.signTransaction(tx, userSolKeypair)
711
+ return await this.sendTx(tx)
712
+ }
713
+
714
+ /**
715
+ * Creates a solana transaction for deletePlaylist
716
+ *
717
+ * @return {Promise<any>}
718
+ * @memberof SolanaWeb3Manager
719
+ */
720
+ async deletePlaylist(
721
+ params: OmitAndRequire<
722
+ AudiusData.DeleteEntityParams,
723
+ 'program',
724
+ 'id' | 'userId'
725
+ >
726
+ ) {
727
+ if (!this.didInit()) return
728
+
729
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
730
+ await this.getUserIdSeed(params.userId)
731
+
732
+ const userSolKeypair = this.getUserKeyPair()
733
+ const tx = AudiusData.deletePlaylist({
734
+ program: this.program,
735
+ adminAccount: this.adminAccount,
736
+ baseAuthorityAccount,
737
+ bumpSeed,
738
+ userAccount,
739
+ userAuthorityPublicKey: userSolKeypair.publicKey,
740
+ userAuthorityDelegateAccount: SystemProgram.programId,
741
+ authorityDelegationStatusAccount: SystemProgram.programId,
742
+ ...params
743
+ })
744
+ await this.signTransaction(tx, userSolKeypair)
745
+ return await this.sendTx(tx)
746
+ }
747
+
748
+ // ============================= SOCIAL ACTIONS =============================
749
+
750
+ /**
751
+ * Creates a solana transaction for addTrackRepost
752
+ *
753
+ * @return {Promise<any>}
754
+ * @memberof SolanaWeb3Manager
755
+ */
756
+ async addTrackSave(
757
+ params: OmitAndRequire<
758
+ AudiusData.EntitySocialActionParams,
759
+ 'program',
760
+ 'id' | 'userId'
761
+ >
762
+ ) {
763
+ if (!this.didInit()) return
764
+
765
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
766
+ await this.getUserIdSeed(params.userId)
767
+
768
+ const userSolKeypair = this.getUserKeyPair()
769
+ const tx = AudiusData.addTrackSave({
770
+ program: this.program,
771
+ adminAccount: this.adminAccount,
772
+ baseAuthorityAccount,
773
+ bumpSeed,
774
+ userAccount,
775
+ userAuthorityPublicKey: userSolKeypair.publicKey,
776
+ userAuthorityDelegateAccount: SystemProgram.programId,
777
+ authorityDelegationStatusAccount: SystemProgram.programId,
778
+ ...params
779
+ })
780
+ await this.signTransaction(tx, userSolKeypair)
781
+ return await this.sendTx(tx)
782
+ }
783
+
784
+ /**
785
+ * Creates a solana transaction for deleteTrackSave
786
+ *
787
+ * @return {Promise<any>}
788
+ * @memberof SolanaWeb3Manager
789
+ */
790
+ async deleteTrackSave(
791
+ params: OmitAndRequire<
792
+ AudiusData.EntitySocialActionParams,
793
+ 'program',
794
+ 'id' | 'userId'
795
+ >
796
+ ) {
797
+ if (!this.didInit()) return
798
+
799
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
800
+ await this.getUserIdSeed(params.userId)
801
+
802
+ const userSolKeypair = this.getUserKeyPair()
803
+ const tx = AudiusData.deleteTrackSave({
804
+ program: this.program,
805
+ adminAccount: this.adminAccount,
806
+ baseAuthorityAccount,
807
+ bumpSeed,
808
+ userAccount,
809
+ userAuthorityPublicKey: userSolKeypair.publicKey,
810
+ userAuthorityDelegateAccount: SystemProgram.programId,
811
+ authorityDelegationStatusAccount: SystemProgram.programId,
812
+ ...params
813
+ })
814
+ await this.signTransaction(tx, userSolKeypair)
815
+ return await this.sendTx(tx)
816
+ }
817
+
818
+ /**
819
+ * Creates a solana transaction for addTrackRepost
820
+ *
821
+ * @return {Promise<any>}
822
+ * @memberof SolanaWeb3Manager
823
+ */
824
+ async addTrackRepost(
825
+ params: OmitAndRequire<
826
+ AudiusData.EntitySocialActionParams,
827
+ 'program',
828
+ 'id' | 'userId'
829
+ >
830
+ ) {
831
+ if (!this.didInit()) return
832
+
833
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
834
+ await this.getUserIdSeed(params.userId)
835
+
836
+ const userSolKeypair = this.getUserKeyPair()
837
+ const tx = AudiusData.addTrackRepost({
838
+ program: this.program,
839
+ adminAccount: this.adminAccount,
840
+ baseAuthorityAccount,
841
+ bumpSeed,
842
+ userAccount,
843
+ userAuthorityPublicKey: userSolKeypair.publicKey,
844
+ userAuthorityDelegateAccount: SystemProgram.programId,
845
+ authorityDelegationStatusAccount: SystemProgram.programId,
846
+ ...params
847
+ })
848
+ await this.signTransaction(tx, userSolKeypair)
849
+ return await this.sendTx(tx)
850
+ }
851
+
852
+ /**
853
+ * Creates a solana transaction for deleteTrackRepost
854
+ *
855
+ * @return {Promise<any>}
856
+ * @memberof SolanaWeb3Manager
857
+ */
858
+ async deleteTrackRepost(
859
+ params: OmitAndRequire<
860
+ AudiusData.EntitySocialActionParams,
861
+ 'program',
862
+ 'id' | 'userId'
863
+ >
864
+ ) {
865
+ if (!this.didInit()) return
866
+
867
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
868
+ await this.getUserIdSeed(params.userId)
869
+
870
+ const userSolKeypair = this.getUserKeyPair()
871
+ const tx = AudiusData.deleteTrackRepost({
872
+ program: this.program,
873
+ adminAccount: this.adminAccount,
874
+ baseAuthorityAccount,
875
+ bumpSeed,
876
+ userAccount,
877
+ userAuthorityPublicKey: userSolKeypair.publicKey,
878
+ userAuthorityDelegateAccount: SystemProgram.programId,
879
+ authorityDelegationStatusAccount: SystemProgram.programId,
880
+ ...params
881
+ })
882
+ await this.signTransaction(tx, userSolKeypair)
883
+ return await this.sendTx(tx)
884
+ }
885
+
886
+ /**
887
+ * Creates a solana transaction for addPlaylistSave
888
+ *
889
+ * @return {Promise<any>}
890
+ * @memberof SolanaWeb3Manager
891
+ */
892
+ async addPlaylistSave(
893
+ params: OmitAndRequire<
894
+ AudiusData.EntitySocialActionParams,
895
+ 'program',
896
+ 'id' | 'userId'
897
+ >
898
+ ) {
899
+ if (!this.didInit()) return
900
+
901
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
902
+ await this.getUserIdSeed(params.userId)
903
+
904
+ const userSolKeypair = this.getUserKeyPair()
905
+ const tx = AudiusData.addPlaylistSave({
906
+ program: this.program,
907
+ adminAccount: this.adminAccount,
908
+ baseAuthorityAccount,
909
+ bumpSeed,
910
+ userAccount,
911
+ userAuthorityPublicKey: userSolKeypair.publicKey,
912
+ userAuthorityDelegateAccount: SystemProgram.programId,
913
+ authorityDelegationStatusAccount: SystemProgram.programId,
914
+ ...params
915
+ })
916
+ await this.signTransaction(tx, userSolKeypair)
917
+ return await this.sendTx(tx)
918
+ }
919
+
920
+ /**
921
+ * Creates a solana transaction for deletePlaylistSave
922
+ *
923
+ * @return {Promise<any>}
924
+ * @memberof SolanaWeb3Manager
925
+ */
926
+ async deletePlaylistSave(
927
+ params: OmitAndRequire<
928
+ AudiusData.EntitySocialActionParams,
929
+ 'program',
930
+ 'id' | 'userId'
931
+ >
932
+ ) {
933
+ if (!this.didInit()) return
934
+
935
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
936
+ await this.getUserIdSeed(params.userId)
937
+
938
+ const userSolKeypair = this.getUserKeyPair()
939
+ const tx = AudiusData.deletePlaylistSave({
940
+ program: this.program,
941
+ adminAccount: this.adminAccount,
942
+ baseAuthorityAccount,
943
+ bumpSeed,
944
+ userAccount,
945
+ userAuthorityPublicKey: userSolKeypair.publicKey,
946
+ userAuthorityDelegateAccount: SystemProgram.programId,
947
+ authorityDelegationStatusAccount: SystemProgram.programId,
948
+ ...params
949
+ })
950
+ await this.signTransaction(tx, userSolKeypair)
951
+ return await this.sendTx(tx)
952
+ }
953
+
954
+ /**
955
+ * Creates a solana transaction for addPlaylistRepost
956
+ *
957
+ * @return {Promise<any>}
958
+ * @memberof SolanaWeb3Manager
959
+ */
960
+ async addPlaylistRepost(
961
+ params: OmitAndRequire<
962
+ AudiusData.EntitySocialActionParams,
963
+ 'program',
964
+ 'id' | 'userId'
965
+ >
966
+ ) {
967
+ if (!this.didInit()) return
968
+
969
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
970
+ await this.getUserIdSeed(params.userId)
971
+
972
+ const userSolKeypair = this.getUserKeyPair()
973
+ const tx = AudiusData.addPlaylistRepost({
974
+ program: this.program,
975
+ adminAccount: this.adminAccount,
976
+ baseAuthorityAccount,
977
+ bumpSeed,
978
+ userAccount,
979
+ userAuthorityPublicKey: userSolKeypair.publicKey,
980
+ userAuthorityDelegateAccount: SystemProgram.programId,
981
+ authorityDelegationStatusAccount: SystemProgram.programId,
982
+ ...params
983
+ })
984
+ await this.signTransaction(tx, userSolKeypair)
985
+ return await this.sendTx(tx)
986
+ }
987
+
988
+ /**
989
+ * Creates a solana transaction for deletePlaylistRepost
990
+ *
991
+ * @return {Promise<any>}
992
+ * @memberof SolanaWeb3Manager
993
+ */
994
+ async deletePlaylistRepost(
995
+ params: OmitAndRequire<
996
+ AudiusData.EntitySocialActionParams,
997
+ 'program',
998
+ 'id' | 'userId'
999
+ >
1000
+ ) {
1001
+ if (!this.didInit()) return
1002
+
1003
+ const { bumpSeed, baseAuthorityAccount, userAccount } =
1004
+ await this.getUserIdSeed(params.userId)
1005
+
1006
+ const userSolKeypair = this.getUserKeyPair()
1007
+ const tx = AudiusData.deletePlaylistRepost({
1008
+ program: this.program,
1009
+ adminAccount: this.adminAccount,
1010
+ baseAuthorityAccount,
1011
+ bumpSeed,
1012
+ userAccount,
1013
+ userAuthorityPublicKey: userSolKeypair.publicKey,
1014
+ userAuthorityDelegateAccount: SystemProgram.programId,
1015
+ authorityDelegationStatusAccount: SystemProgram.programId,
1016
+ ...params
1017
+ })
1018
+ await this.signTransaction(tx, userSolKeypair)
1019
+ return await this.sendTx(tx)
1020
+ }
1021
+
1022
+ // ============================= USER ACTIONS =============================
1023
+
1024
+ /**
1025
+ * Creates a solana transaction for followUser
1026
+ *
1027
+ * @return {Promise<any>}
1028
+ * @memberof SolanaWeb3Manager
1029
+ */
1030
+ async followUser(
1031
+ params: OmitAndRequire<
1032
+ AudiusData.UserSocialActionParams,
1033
+ 'program',
1034
+ 'sourceUserId' | 'targetUserId'
1035
+ >
1036
+ ) {
1037
+ if (!this.didInit()) return
1038
+
1039
+ const {
1040
+ bumpSeed: sourceUserBumpSeed,
1041
+ baseAuthorityAccount,
1042
+ userAccount: sourceUserAccount
1043
+ } = await this.getUserIdSeed(params.sourceUserId)
1044
+ const { bumpSeed: targetUserBumpSeed, userAccount: targetUserAccount } =
1045
+ await this.getUserIdSeed(params.targetUserId)
1046
+
1047
+ const userSolKeypair = this.getUserKeyPair()
1048
+
1049
+ const tx = AudiusData.followUser({
1050
+ program: this.program,
1051
+ adminAccount: this.adminAccount,
1052
+ baseAuthorityAccount,
1053
+ sourceUserAccount,
1054
+ sourceUserBumpSeed,
1055
+ targetUserAccount,
1056
+ targetUserBumpSeed,
1057
+ userAuthorityPublicKey: userSolKeypair.publicKey,
1058
+ userAuthorityDelegateAccount: SystemProgram.programId,
1059
+ authorityDelegationStatusAccount: SystemProgram.programId,
1060
+ ...params
1061
+ })
1062
+ await this.signTransaction(tx, userSolKeypair)
1063
+ return await this.sendTx(tx)
1064
+ }
1065
+
1066
+ /**
1067
+ * Creates a solana transaction for unfollowUser
1068
+ *
1069
+ * @return {Promise<any>}
1070
+ * @memberof SolanaWeb3Manager
1071
+ */
1072
+ async unfollowUser(
1073
+ params: OmitAndRequire<
1074
+ AudiusData.UserSocialActionParams,
1075
+ 'program',
1076
+ 'sourceUserId' | 'targetUserId'
1077
+ >
1078
+ ) {
1079
+ if (!this.didInit()) return
1080
+
1081
+ const {
1082
+ bumpSeed: sourceUserBumpSeed,
1083
+ baseAuthorityAccount,
1084
+ userAccount: sourceUserAccount
1085
+ } = await this.getUserIdSeed(params.sourceUserId)
1086
+ const { bumpSeed: targetUserBumpSeed, userAccount: targetUserAccount } =
1087
+ await this.getUserIdSeed(params.targetUserId)
1088
+
1089
+ const userSolKeypair = this.getUserKeyPair()
1090
+ const tx = AudiusData.unfollowUser({
1091
+ program: this.program,
1092
+ adminAccount: this.adminAccount,
1093
+ baseAuthorityAccount,
1094
+ sourceUserAccount,
1095
+ sourceUserBumpSeed,
1096
+ targetUserAccount,
1097
+ targetUserBumpSeed,
1098
+ userAuthorityPublicKey: userSolKeypair.publicKey,
1099
+ userAuthorityDelegateAccount: SystemProgram.programId,
1100
+ authorityDelegationStatusAccount: SystemProgram.programId,
1101
+ ...params
1102
+ })
1103
+ await this.signTransaction(tx, userSolKeypair)
1104
+ return await this.sendTx(tx)
1105
+ }
1106
+
1107
+ /**
1108
+ * Creates a solana transaction for subscribeUser
1109
+ *
1110
+ * @return {Promise<any>}
1111
+ * @memberof SolanaWeb3Manager
1112
+ */
1113
+ async subscribeUser(
1114
+ params: OmitAndRequire<
1115
+ AudiusData.UserSocialActionParams,
1116
+ 'program',
1117
+ 'sourceUserId' | 'targetUserId'
1118
+ >
1119
+ ) {
1120
+ if (!this.didInit()) return
1121
+
1122
+ const {
1123
+ bumpSeed: sourceUserBumpSeed,
1124
+ baseAuthorityAccount,
1125
+ userAccount: sourceUserAccount
1126
+ } = await this.getUserIdSeed(params.sourceUserId)
1127
+ const { bumpSeed: targetUserBumpSeed, userAccount: targetUserAccount } =
1128
+ await this.getUserIdSeed(params.targetUserId)
1129
+
1130
+ const userSolKeypair = this.getUserKeyPair()
1131
+ const tx = AudiusData.subscribeUser({
1132
+ program: this.program,
1133
+ adminAccount: this.adminAccount,
1134
+ baseAuthorityAccount,
1135
+ sourceUserAccount,
1136
+ sourceUserBumpSeed,
1137
+ targetUserAccount,
1138
+ targetUserBumpSeed,
1139
+ userAuthorityPublicKey: userSolKeypair.publicKey,
1140
+ userAuthorityDelegateAccount: SystemProgram.programId,
1141
+ authorityDelegationStatusAccount: SystemProgram.programId,
1142
+ ...params
1143
+ })
1144
+ await this.signTransaction(tx, userSolKeypair)
1145
+ return await this.sendTx(tx)
1146
+ }
1147
+
1148
+ /**
1149
+ * Creates a solana transaction for unsubscribeUser
1150
+ *
1151
+ * @return {Promise<any>}
1152
+ * @memberof SolanaWeb3Manager
1153
+ */
1154
+ async unsubscribeUser(
1155
+ params: OmitAndRequire<
1156
+ AudiusData.UserSocialActionParams,
1157
+ 'program',
1158
+ 'sourceUserId' | 'targetUserId'
1159
+ >
1160
+ ) {
1161
+ if (!this.didInit()) return
1162
+
1163
+ const {
1164
+ bumpSeed: sourceUserBumpSeed,
1165
+ baseAuthorityAccount,
1166
+ userAccount: sourceUserAccount
1167
+ } = await this.getUserIdSeed(params.sourceUserId)
1168
+ const { bumpSeed: targetUserBumpSeed, userAccount: targetUserAccount } =
1169
+ await this.getUserIdSeed(params.targetUserId)
1170
+
1171
+ const userSolKeypair = this.getUserKeyPair()
1172
+
1173
+ const tx = AudiusData.unsubscribeUser({
1174
+ program: this.program,
1175
+ adminAccount: this.adminAccount,
1176
+ baseAuthorityAccount,
1177
+ sourceUserAccount,
1178
+ sourceUserBumpSeed,
1179
+ targetUserAccount,
1180
+ targetUserBumpSeed,
1181
+ userAuthorityPublicKey: userSolKeypair.publicKey,
1182
+ userAuthorityDelegateAccount: SystemProgram.programId,
1183
+ authorityDelegationStatusAccount: SystemProgram.programId,
1184
+ ...params
1185
+ })
1186
+ await this.signTransaction(tx, userSolKeypair)
1187
+ return await this.sendTx(tx)
1188
+ }
1189
+ }