@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,131 @@
1
+ const Web3 = require('../src/web3')
2
+ const path = require('path')
3
+
4
+ const { setServiceVersion, addServiceType } = require('./helpers/version')
5
+ const { getStakingParameters } = require('./helpers/spRegistration')
6
+ const { getClaimInfo, fundNewClaim } = require('./helpers/claim')
7
+
8
+ const AudiusLibs = require('../src/index')
9
+
10
+ const isServer = true
11
+
12
+ const args = process.argv
13
+ if (args.length < 3) {
14
+ _throwArgError()
15
+ }
16
+
17
+ /*
18
+ *
19
+ * export AUDIUS_PRIVATE_KEY=
20
+ export AUDIUS_OWNER_WALLET=
21
+ * */
22
+ const run = async () => {
23
+ try {
24
+ const configFile = args[2]
25
+ const commandToRun = args[3]
26
+ const config = require(path.join(__dirname, configFile))
27
+
28
+ const privateKey = _getEnv('AUDIUS_PRIVATE_KEY')
29
+ const ownerWallet = _getEnv('AUDIUS_OWNER_WALLET')
30
+ const audiusLibs = await getAudiusLibs(config, privateKey, ownerWallet)
31
+ switch (commandToRun) {
32
+ case 'setversion':
33
+ const serviceType = args[4]
34
+ const versionStr = args[5]
35
+ let dryRun = true
36
+ // if args[6] is defined and the value is either bool or string false, set dryRun to false
37
+ if (args[6] && (['false', false].includes(args[6]))) {
38
+ dryRun = false
39
+ }
40
+ if (!serviceType || !versionStr) {
41
+ throw new Error('missing arguments - format: node mainnet.js setversion <serviceType> <versionStr>')
42
+ }
43
+ await setServiceVersion(audiusLibs, serviceType, versionStr, privateKey, dryRun)
44
+ break
45
+ case 'addservicetype':
46
+ const newServiceType = args[4]
47
+ const serviceTypeMin = args[5]
48
+ const serviceTypeMax = args[6]
49
+ if (!newServiceType || !serviceTypeMin || !serviceTypeMax) {
50
+ throw new Error('missing arguments - format: node mainnet.js addservicetype <serviceType> <serviceTypeMin> <serviceTypeMax>')
51
+ }
52
+ await addServiceType(audiusLibs, newServiceType, serviceTypeMin, serviceTypeMax, privateKey)
53
+ break
54
+ case 'getclaim':
55
+ await getClaimInfo(audiusLibs)
56
+ break
57
+ case 'fundclaim':
58
+ if (!args[4]) {
59
+ throw new Error('missing argument - format: node mainnet.js fundclaim <amountOfAuds>')
60
+ }
61
+
62
+ const amountOfAuds = args[4]
63
+ await fundNewClaim(audiusLibs, amountOfAuds, privateKey)
64
+ break
65
+ case 'stakeinfo':
66
+ await getStakingParameters(audiusLibs)
67
+ break
68
+ default:
69
+ _throwArgError()
70
+ }
71
+
72
+ process.exit(0)
73
+ } catch (e) {
74
+ throw e
75
+ }
76
+ }
77
+
78
+ run()
79
+
80
+ function getLibsConfig (config, privateKey, ownerWallet) {
81
+ let audiusLibsConfig
82
+ if (!privateKey || !ownerWallet) {
83
+ throw new Error('Missing private key or owner wallet')
84
+ }
85
+ console.log('Querying environment variables:')
86
+ console.log(privateKey)
87
+ console.log(ownerWallet)
88
+
89
+ const dataWeb3 = new Web3(new Web3.providers.HttpProvider(config.dataWeb3ProviderEndpoint))
90
+ const web3DataContractConfig = {
91
+ registryAddress: config.dataRegistryAddress,
92
+ useExternalWeb3: true,
93
+ externalWeb3Config: {
94
+ web3: dataWeb3,
95
+ ownerWallet: ownerWallet
96
+ }
97
+ }
98
+
99
+ const ethWeb3 = new Web3(new Web3.providers.HttpProvider(config.ethWeb3ProviderEndpoint))
100
+ audiusLibsConfig = {
101
+ web3Config: web3DataContractConfig,
102
+ ethWeb3Config: AudiusLibs.configEthWeb3(
103
+ config.ethTokenAddress, // Token Address
104
+ config.ethRegistryAddress,
105
+ ethWeb3,
106
+ ownerWallet
107
+ ),
108
+ discoveryProviderConfig: AudiusLibs.configDiscoveryProvider(),
109
+ isServer: isServer
110
+ }
111
+ return audiusLibsConfig
112
+ }
113
+
114
+ async function getAudiusLibs (config, privateKey, ownerWallet) {
115
+ const audiusLibsConfig = getLibsConfig(config, privateKey, ownerWallet)
116
+ const audiusLibs = new AudiusLibs(audiusLibsConfig)
117
+ await audiusLibs.init()
118
+ return audiusLibs
119
+ }
120
+
121
+ function _getEnv (env) {
122
+ const value = process.env[env]
123
+ if (typeof value === 'undefined') {
124
+ throw new Error(`${env} has not been set.`)
125
+ }
126
+ return value
127
+ }
128
+
129
+ function _throwArgError () {
130
+ throw new Error('missing argument - format: node mainnet.js <configFilePath> [setversion, fundclaim, getclaim, stakeinfo] [additional options]')
131
+ }
@@ -0,0 +1,191 @@
1
+ const Web3 = require('web3')
2
+ const crypto = require('crypto')
3
+ const EthereumWallet = require('ethereumjs-wallet')
4
+ const EthereumTx = require('ethereumjs-tx').Transaction
5
+ const axios = require('axios')
6
+
7
+ // Switch to mainnet eth - ropsten is enabled by default to prevent accidental prod manipulation
8
+ // const ethWeb3ProviderEndpoint = 'https://ropsten.infura.io/v3/c569c6faf4f14d15a49d0044e7ddd668'
9
+ const ethWeb3ProviderEndpoint = 'https://mainnet.infura.io/v3/3a78237a7f4f42e69cf69cf9db7cecd6'
10
+ // const ethWeb3ProviderEndpoint = 'https://eth-mainnet.alchemyapi.io/v2/iSnek4T02BFCUEkcPGKo0eEY1aWLJgxF'
11
+
12
+ const fs = require('fs')
13
+
14
+ // 0.0001 ETH, 100000000000000 wei
15
+
16
+ // TBD: Actual target minimum for each relayer
17
+ // const minimumBalance = 100000000000000
18
+
19
+ // 0.1 eth = 100000000000000000 wei
20
+
21
+ // 0.25 eth = 250000000000000000
22
+ // const minimumBalance = 250000000000000000
23
+ // 0.075 eth
24
+ const minimumBalance = 75000000000000000
25
+
26
+ const ethWeb3 = new Web3(new Web3.providers.HttpProvider(ethWeb3ProviderEndpoint))
27
+
28
+ /*
29
+ Expected format of prod-relayer-config.json
30
+ {
31
+ "funderPublicKey": "0x755f4...",
32
+ "funderPrivateKey": "5d30...",
33
+ "relayerWallets": [
34
+ { "publicKey": "0x2c3...",
35
+ "privateKey":
36
+ "d77e00f6..." },
37
+ ...]
38
+ }
39
+ */
40
+
41
+ /**
42
+ * Make sure you save the `prod-relayer-config.json` file from LastPass to libs/initScripts
43
+ */
44
+
45
+ const configFilePath = './prod-relayer-config.json'
46
+ if (!fs.existsSync(configFilePath)) {
47
+ throw new Error('Please ensure you have prod-relayer-config.json saved locally and have set the path')
48
+ }
49
+
50
+ const prodRelayerInfo = require(configFilePath)
51
+
52
+ const generateNewAccounts = async () => {
53
+ const numWallets = 1
54
+ const wallets = []
55
+ for (let i = 0; i < numWallets; i++) {
56
+ const privateKey = crypto.randomBytes(32).toString('hex')
57
+ const privateKeyBuffer = Buffer.from(privateKey, 'hex')
58
+ const walletObj = EthereumWallet.fromPrivateKey(privateKeyBuffer)
59
+ const info = {
60
+ publicKey: walletObj.getAddressString(),
61
+ privateKey
62
+ }
63
+ wallets.push(info)
64
+ }
65
+ console.log(wallets)
66
+ await queryAccountBalances(wallets)
67
+ }
68
+
69
+ const queryAccountBalances = async (wallets) => {
70
+ for (let i = 0; i < wallets.length; i++) {
71
+ const pubKey = wallets[i].publicKey
72
+ const balance = await ethWeb3.eth.getBalance(pubKey)
73
+ console.log(`Found balance ${ethWeb3.utils.fromWei(balance)} eth (${balance} wei) for ${pubKey}`)
74
+ }
75
+ console.log(`\n\nQueried ${wallets.length} wallets`)
76
+ }
77
+
78
+ const queryRelayerBalances = async () => {
79
+ const gasInfo = await getGasPrice()
80
+ const walletInfo = await loadProdRelayerWallets()
81
+ await queryAccountBalances(walletInfo.relayerWallets)
82
+ console.log(gasInfo, '\n')
83
+ }
84
+
85
+ const loadProdRelayerWallets = async () => {
86
+ const funder = {
87
+ publicKey: prodRelayerInfo.funderPublicKey,
88
+ privateKey: prodRelayerInfo.funderPrivateKey
89
+ }
90
+ // console.log(funder)
91
+ const relayerWallets = prodRelayerInfo.relayerWallets
92
+ // console.log(relayerWallets)
93
+ const funderbalance = await ethWeb3.eth.getBalance(funder.publicKey)
94
+ console.log(`\nFunder ${funder.publicKey} balance: ${ethWeb3.utils.fromWei(funderbalance)} eth (${funderbalance} wei)`)
95
+
96
+ console.log(`Minimum relayer balance: ${ethWeb3.utils.fromWei(minimumBalance.toString())} eth (${minimumBalance.toString()} wei)\n\n`)
97
+
98
+ return { funder, relayerWallets }
99
+ }
100
+
101
+ const getGasPrice = async () => {
102
+ const { data } = await axios({
103
+ url: 'https://identityservice.staging.audius.co/eth_gas_price',
104
+ method: 'get',
105
+ timeout: 3000
106
+ })
107
+ return data
108
+ }
109
+
110
+ const createAndSendTransaction = async (sender, receiverAddress, value, web3, gasPrice) => {
111
+ const privateKeyBuffer = Buffer.from(sender.privateKey, 'hex')
112
+ const walletAddress = EthereumWallet.fromPrivateKey(privateKeyBuffer)
113
+ const address = walletAddress.getAddressString()
114
+ // "averageGweiHex": "0x1e08ffca00",
115
+ // const gasPrice = "0x1e08ffca00"
116
+ // fast price = 0x8d8f9fc00
117
+ // new fast price = 0x2e90edd000
118
+ // const gasPrice = "0x2e90edd000"
119
+ // const gasPrice = "0x1e80355e00"
120
+ // from identity - 0xf7100
121
+ const gasLimit = '0xf7100'
122
+ const nonce = await web3.eth.getTransactionCount(address)
123
+ console.log(`Sending tx from ${sender.publicKey} to ${receiverAddress} with nonce=${nonce}, gasPrice=${gasPrice}, gasLimit=${gasLimit}`)
124
+ const txParams = {
125
+ nonce: web3.utils.toHex(nonce),
126
+ gasPrice: gasPrice,
127
+ gasLimit: gasLimit,
128
+ to: receiverAddress,
129
+ value: web3.utils.toHex(value)
130
+ }
131
+ const tx = new EthereumTx(txParams)
132
+ tx.sign(privateKeyBuffer)
133
+ const signedTx = '0x' + tx.serialize().toString('hex')
134
+ try {
135
+ await web3.eth.sendSignedTransaction(signedTx)
136
+ } catch (e) {
137
+ console.log(`Failed with ${e}`)
138
+ }
139
+ }
140
+
141
+ const fundEthRelayerIfEmpty = async () => {
142
+ const walletInfo = await loadProdRelayerWallets()
143
+
144
+ const relayerWallets = walletInfo.relayerWallets
145
+
146
+ let gasInfo
147
+ let gasPrice
148
+
149
+ for (let i = 0; i < relayerWallets.length; i++) {
150
+ const relayerPublicKey = relayerWallets[i].publicKey
151
+ let balance = await ethWeb3.eth.getBalance(relayerPublicKey)
152
+ const validBalance = parseInt(balance) >= minimumBalance
153
+ console.log(`${i + 1} - Found balance ${balance} for ${relayerPublicKey}, validBal=${validBalance}`)
154
+ if (!validBalance) {
155
+ const missingBalance = minimumBalance - balance
156
+ console.log(`${i + 1} - Funding ${relayerPublicKey} with ${missingBalance}, currently ${balance}/${minimumBalance}`)
157
+ gasInfo = await getGasPrice()
158
+ gasPrice = gasInfo.fastestGweiHex
159
+ await createAndSendTransaction(
160
+ walletInfo.funder, // Always send from the designated FUNDER
161
+ relayerPublicKey, // Public key of receiving account
162
+ missingBalance, // Min
163
+ ethWeb3,
164
+ gasPrice
165
+ )
166
+ console.log(`${i + 1} - Finished Funding ${relayerPublicKey} with ${minimumBalance}`)
167
+ balance = await ethWeb3.eth.getBalance(relayerPublicKey)
168
+ console.log(`${i + 1} - Updated balance ${balance} for ${relayerPublicKey}`)
169
+ }
170
+ }
171
+ await queryAccountBalances(relayerWallets)
172
+ }
173
+
174
+ const args = process.argv
175
+ const run = async () => {
176
+ switch (args[2]) {
177
+ case 'fundAllRelayers':
178
+ await fundEthRelayerIfEmpty()
179
+ break
180
+ case 'queryRelayerBalances':
181
+ await queryRelayerBalances()
182
+ break
183
+ case 'generatenewAccounts':
184
+ await generateNewAccounts()
185
+ break
186
+ default:
187
+ throw new Error('Invalid argument')
188
+ }
189
+ }
190
+
191
+ run()
package/package.json ADDED
@@ -0,0 +1,125 @@
1
+ {
2
+ "name": "@audius/sdk",
3
+ "version": "0.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/types.d.ts",
7
+ "browser": "dist/browser.js",
8
+ "legacy": "dist/legacy.js",
9
+ "legacyTypes": "dist/legacy.d.ts",
10
+ "core": "dist/core.js",
11
+ "coreTypes": "dist/core.d.ts",
12
+ "scripts": {
13
+ "init-local": "ts-node initScripts/local.js",
14
+ "test": "./scripts/test.sh",
15
+ "test-circle-ci": "./scripts/circleci-test.sh",
16
+ "test:unit": "ts-mocha 'src/**/*.test.{js,ts}' --exit",
17
+ "test:unit:watch": "ts-mocha 'src/**/*.test.{js,ts}' --watch",
18
+ "test:integration": "ts-mocha tests/index.js",
19
+ "setup": "./scripts/migrate_contracts.sh",
20
+ "build": "rollup -c",
21
+ "dev": "rollup -c -w",
22
+ "lint": "eslint ./src ./types",
23
+ "lint:fix": "npm run lint -- --fix",
24
+ "typecheck": "tsc --noEmit"
25
+ },
26
+ "dependencies": {
27
+ "@audius/anchor-audius-data": "0.0.2",
28
+ "@audius/hedgehog": "1.0.12",
29
+ "@certusone/wormhole-sdk": "0.1.1",
30
+ "@ethersproject/solidity": "5.0.5",
31
+ "@improbable-eng/grpc-web-node-http-transport": "0.15.0",
32
+ "@project-serum/anchor": "0.24.1",
33
+ "@solana/spl-token": "0.1.6",
34
+ "@solana/web3.js": "1.37.1",
35
+ "abi-decoder": "1.2.0",
36
+ "ajv": "6.12.2",
37
+ "async-retry": "1.3.1",
38
+ "axios": "0.19.2",
39
+ "borsh": "0.4.0",
40
+ "bs58": "4.0.1",
41
+ "cipher-base": "1.0.4",
42
+ "elliptic": "6.5.4",
43
+ "esm": "3.2.25",
44
+ "eth-sig-util": "2.5.4",
45
+ "ethereumjs-tx": "2.1.2",
46
+ "ethereumjs-util": "7.1.4",
47
+ "ethereumjs-wallet": "1.0.2",
48
+ "ethers": "5.4.7",
49
+ "form-data": "3.0.0",
50
+ "hashids": "2.2.10",
51
+ "interface-blockstore": "^2.0.3",
52
+ "interface-store": "^2.0.2",
53
+ "ipfs-unixfs-importer": "^9.0.6",
54
+ "jsonschema": "1.2.6",
55
+ "keccak256": "1.0.2",
56
+ "lodash": "4.17.21",
57
+ "node-localstorage": "^1.3.1",
58
+ "proper-url-join": "1.2.0",
59
+ "rollup-plugin-shim": "^1.0.0",
60
+ "safe-buffer": "5.2.1",
61
+ "secp256k1": "4.0.2",
62
+ "semver": "6.3.0",
63
+ "stream-browserify": "3.0.0",
64
+ "web3": "1.7.1"
65
+ },
66
+ "devDependencies": {
67
+ "@babel/preset-env": "7.16.11",
68
+ "@openzeppelin/test-helpers": "0.5.6",
69
+ "@rollup/plugin-alias": "3.1.9",
70
+ "@rollup/plugin-babel": "5.3.1",
71
+ "@rollup/plugin-commonjs": "21.0.2",
72
+ "@rollup/plugin-json": "4.1.0",
73
+ "@rollup/plugin-node-resolve": "13.1.3",
74
+ "@rollup/plugin-typescript": "8.3.1",
75
+ "@tsconfig/node16-strictest": "1.0.0",
76
+ "@types/async-retry": "1.4.3",
77
+ "@types/bn.js": "5.1.0",
78
+ "@types/bs58": "4.0.1",
79
+ "@types/eth-sig-util": "^2.1.1",
80
+ "@types/expect": "24.3.0",
81
+ "@types/form-data": "^2.5.0",
82
+ "@types/hashids": "2.0.1",
83
+ "@types/mocha": "9.1.0",
84
+ "@types/node-localstorage": "1.3.0",
85
+ "@types/pify": "^5.0.1",
86
+ "@types/proper-url-join": "2.1.1",
87
+ "@types/semver": "7.3.9",
88
+ "@typescript-eslint/eslint-plugin": "4.33.0",
89
+ "eslint": "7.32.0",
90
+ "eslint-config-prettier": "^8.5.0",
91
+ "eslint-config-standard-with-typescript": "21.0.1",
92
+ "eslint-plugin-import": "2.25.4",
93
+ "eslint-plugin-mocha": "10.0.3",
94
+ "eslint-plugin-node": "11.1.0",
95
+ "eslint-plugin-prettier": "^4.0.0",
96
+ "eslint-plugin-promise": "5.2.0",
97
+ "mocha": "9.2.2",
98
+ "nock": "13.1.2",
99
+ "nyc": "15.1.0",
100
+ "prettier": "^2.6.1",
101
+ "prettier-config-standard": "^5.0.0",
102
+ "rollup": "2.70.1",
103
+ "rollup-plugin-dts": "4.2.0",
104
+ "rollup-plugin-ignore": "1.0.10",
105
+ "rollup-plugin-polyfill-node": "0.9.0",
106
+ "sinon": "9.0.2",
107
+ "standard": "16.0.4",
108
+ "ts-mocha": "9.0.2",
109
+ "ts-node": "10.7.0",
110
+ "typescript": "4.6.2"
111
+ },
112
+ "repository": {
113
+ "type": "git",
114
+ "url": "git+https://github.com/AudiusProject/audius-protocol/tree/master/libs"
115
+ },
116
+ "engines": {
117
+ "node": ">=14.0.0"
118
+ },
119
+ "author": "Audius",
120
+ "license": "Apache-2.0",
121
+ "bugs": {
122
+ "url": "https://github.com/AudiusProject/audius-protocol/issues"
123
+ },
124
+ "homepage": "https://github.com/AudiusProject/audius-protocol/tree/master/libs"
125
+ }
@@ -0,0 +1,164 @@
1
+ import commonjs from '@rollup/plugin-commonjs'
2
+ import babel from '@rollup/plugin-babel'
3
+ import json from '@rollup/plugin-json'
4
+ import resolve from '@rollup/plugin-node-resolve'
5
+ import typescript from '@rollup/plugin-typescript'
6
+ import dts from 'rollup-plugin-dts'
7
+ import nodePolyfills from 'rollup-plugin-polyfill-node'
8
+ import alias from '@rollup/plugin-alias'
9
+ import ignore from 'rollup-plugin-ignore'
10
+
11
+ import pkg from './package.json'
12
+
13
+ const extensions = ['.js', '.ts']
14
+
15
+ const external = [
16
+ ...Object.keys(pkg.dependencies),
17
+ ...Object.keys(pkg.devDependencies),
18
+ 'ethers/lib/utils',
19
+ 'ethers/lib/index',
20
+ 'hashids/cjs'
21
+ ]
22
+
23
+ const commonConfig = {
24
+ plugins: [
25
+ commonjs({
26
+ extensions,
27
+ dynamicRequireTargets: [
28
+ 'data-contracts/ABIs/*.json',
29
+ 'eth-contracts/ABIs/*.json'
30
+ ]
31
+ }),
32
+ babel({ babelHelpers: 'bundled', extensions }),
33
+ json(),
34
+ resolve({ extensions, preferBuiltins: true }),
35
+ typescript()
36
+ ],
37
+ external
38
+ }
39
+
40
+ // For the browser bundle, these need to be internal because they either:
41
+ // * contain deps that need to be polyfilled via `nodePolyfills`
42
+ // * are ignored via `ignore`
43
+ const browserInternal = [
44
+ 'eth-sig-util',
45
+ 'ethereumjs-tx',
46
+ 'ethereumjs-util',
47
+ 'ethereumjs-wallet',
48
+ 'graceful-fs',
49
+ 'node-localstorage',
50
+ 'web3'
51
+ ]
52
+
53
+ const browserConfig = {
54
+ plugins: [
55
+ ignore(['web3', 'graceful-fs', 'node-localstorage']),
56
+ resolve({ extensions, preferBuiltins: false }),
57
+ commonjs({
58
+ extensions,
59
+ transformMixedEsModules: true,
60
+ dynamicRequireTargets: [
61
+ 'data-contracts/ABIs/*.json',
62
+ 'eth-contracts/ABIs/*.json'
63
+ ]
64
+ }),
65
+ alias({
66
+ entries: [{ find: 'stream', replacement: 'stream-browserify' }]
67
+ }),
68
+ nodePolyfills(),
69
+ babel({ babelHelpers: 'bundled', extensions }),
70
+ json(),
71
+ typescript()
72
+ ],
73
+ external: external.filter((dep) => !browserInternal.includes(dep))
74
+ }
75
+
76
+ const browserLegacyConfig = {
77
+ plugins: [
78
+ ignore(['web3', 'graceful-fs', 'node-localstorage']),
79
+ resolve({ extensions, preferBuiltins: true }),
80
+ commonjs({
81
+ extensions,
82
+ dynamicRequireTargets: [
83
+ 'data-contracts/ABIs/*.json',
84
+ 'eth-contracts/ABIs/*.json'
85
+ ]
86
+ }),
87
+ alias({
88
+ entries: [{ find: 'stream', replacement: 'stream-browserify' }]
89
+ }),
90
+ babel({ babelHelpers: 'bundled', extensions }),
91
+ json(),
92
+ typescript()
93
+ ],
94
+ external
95
+ }
96
+
97
+ const commonTypeConfig = {
98
+ plugins: [dts()]
99
+ }
100
+
101
+ export default [
102
+ /**
103
+ * SDK
104
+ */
105
+ {
106
+ input: 'src/index.js',
107
+ output: [
108
+ { file: pkg.main, format: 'cjs', exports: 'auto', sourcemap: true }
109
+ ],
110
+ ...commonConfig
111
+ },
112
+
113
+ {
114
+ input: './src/types.ts',
115
+ output: [{ file: pkg.types, format: 'cjs' }],
116
+ ...commonTypeConfig
117
+ },
118
+
119
+ /**
120
+ * SDK bundled for a browser environment (includes polyfills for node libraries)
121
+ * Does not include libs but does include polyfills
122
+ */
123
+ {
124
+ input: 'src/sdk/index.ts',
125
+ output: [
126
+ { file: pkg.browser, format: 'cjs', exports: 'auto', sourcemap: true }
127
+ ],
128
+ ...browserConfig
129
+ },
130
+
131
+ /**
132
+ * Legacy bundle for a browser environment
133
+ * Includes libs but does not include polyfills
134
+ */
135
+ {
136
+ input: 'src/index.js',
137
+ output: [
138
+ { file: pkg.legacy, format: 'cjs', exports: 'auto', sourcemap: true }
139
+ ],
140
+ ...browserLegacyConfig
141
+ },
142
+
143
+ {
144
+ input: './src/types.ts',
145
+ output: [{ file: pkg.legacyTypes, format: 'cjs' }],
146
+ ...commonTypeConfig
147
+ },
148
+
149
+ /**
150
+ * core (used for eager requests)
151
+ */
152
+ {
153
+ input: 'src/core.ts',
154
+ output: [
155
+ { file: pkg.core, format: 'cjs', exports: 'auto', sourcemap: true }
156
+ ],
157
+ ...commonConfig
158
+ },
159
+ {
160
+ input: './src/core.ts',
161
+ output: [{ file: pkg.coreTypes, format: 'cjs' }],
162
+ ...commonTypeConfig
163
+ }
164
+ ]