@audius/sp-actions 1.0.2 → 1.0.4
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.
- package/CHANGELOG.md +18 -0
- package/claim.js +133 -31
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @audius/sp-actions
|
|
2
2
|
|
|
3
|
+
## 1.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [9b58792]
|
|
8
|
+
- Updated dependencies [9694ea4]
|
|
9
|
+
- Updated dependencies [6ee5f42]
|
|
10
|
+
- Updated dependencies [e28b82b]
|
|
11
|
+
- Updated dependencies [0c3f791]
|
|
12
|
+
- @audius/sdk@6.0.0
|
|
13
|
+
|
|
14
|
+
## 1.0.3
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [1c2edae]
|
|
19
|
+
- @audius/sdk@5.1.0
|
|
20
|
+
|
|
3
21
|
## 1.0.2
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/claim.js
CHANGED
|
@@ -5,17 +5,31 @@ const Web3 = require('web3')
|
|
|
5
5
|
const HDWalletProvider = require('@truffle/hdwallet-provider')
|
|
6
6
|
const { program } = require('commander')
|
|
7
7
|
|
|
8
|
-
const { AudiusLibs } = require('@audius/sdk')
|
|
8
|
+
const { AudiusLibs } = require('@audius/sdk/dist/libs')
|
|
9
9
|
|
|
10
10
|
const defaultRegistryAddress = '0xd976d3b4f4e22a238c1A736b6612D22f17b6f64C'
|
|
11
11
|
const defaultTokenAddress = '0x18aAA7115705e8be94bfFEBDE57Af9BFc265B998'
|
|
12
|
-
const defaultWeb3Provider =
|
|
12
|
+
const defaultWeb3Provider =
|
|
13
|
+
'https://eth-mainnet.g.alchemy.com/v2/4hFRA61i6OFXz2UmkyFsSvgXBQBBOGgW'
|
|
13
14
|
|
|
14
|
-
async function configureLibs(
|
|
15
|
-
|
|
15
|
+
async function configureLibs(
|
|
16
|
+
ethRegistryAddress,
|
|
17
|
+
ethTokenAddress,
|
|
18
|
+
web3Provider
|
|
19
|
+
) {
|
|
20
|
+
const configuredWeb3 = await AudiusLibs.Utils.configureWeb3(
|
|
21
|
+
web3Provider,
|
|
22
|
+
null,
|
|
23
|
+
false
|
|
24
|
+
)
|
|
16
25
|
|
|
17
26
|
const audiusLibsConfig = {
|
|
18
|
-
ethWeb3Config: AudiusLibs.configEthWeb3(
|
|
27
|
+
ethWeb3Config: AudiusLibs.configEthWeb3(
|
|
28
|
+
ethTokenAddress,
|
|
29
|
+
ethRegistryAddress,
|
|
30
|
+
configuredWeb3,
|
|
31
|
+
'0x0'
|
|
32
|
+
),
|
|
19
33
|
isServer: true,
|
|
20
34
|
}
|
|
21
35
|
|
|
@@ -25,8 +39,16 @@ async function configureLibs(ethRegistryAddress, ethTokenAddress, web3Provider)
|
|
|
25
39
|
return libs
|
|
26
40
|
}
|
|
27
41
|
|
|
28
|
-
async function getClaimsManagerContract(
|
|
29
|
-
|
|
42
|
+
async function getClaimsManagerContract(
|
|
43
|
+
ethRegistryAddress,
|
|
44
|
+
ethTokenAddress,
|
|
45
|
+
web3
|
|
46
|
+
) {
|
|
47
|
+
const audiusLibs = await configureLibs(
|
|
48
|
+
ethRegistryAddress,
|
|
49
|
+
ethTokenAddress,
|
|
50
|
+
web3.eth.currentProvider
|
|
51
|
+
)
|
|
30
52
|
await audiusLibs.ethContracts.ClaimsManagerClient.init()
|
|
31
53
|
return new web3.eth.Contract(
|
|
32
54
|
audiusLibs.ethContracts.ClaimsManagerClient._contract.options.jsonInterface,
|
|
@@ -34,8 +56,16 @@ async function getClaimsManagerContract(ethRegistryAddress, ethTokenAddress, web
|
|
|
34
56
|
)
|
|
35
57
|
}
|
|
36
58
|
|
|
37
|
-
async function getDelegateManagerContract(
|
|
38
|
-
|
|
59
|
+
async function getDelegateManagerContract(
|
|
60
|
+
ethRegistryAddress,
|
|
61
|
+
ethTokenAddress,
|
|
62
|
+
web3
|
|
63
|
+
) {
|
|
64
|
+
const audiusLibs = await configureLibs(
|
|
65
|
+
ethRegistryAddress,
|
|
66
|
+
ethTokenAddress,
|
|
67
|
+
web3.eth.currentProvider
|
|
68
|
+
)
|
|
39
69
|
await audiusLibs.ethContracts.DelegateManagerClient.init()
|
|
40
70
|
return new web3.eth.Contract(
|
|
41
71
|
audiusLibs.ethContracts.DelegateManagerClient._contract.options.jsonInterface,
|
|
@@ -43,7 +73,17 @@ async function getDelegateManagerContract(ethRegistryAddress, ethTokenAddress, w
|
|
|
43
73
|
)
|
|
44
74
|
}
|
|
45
75
|
|
|
46
|
-
async function initiateRound(
|
|
76
|
+
async function initiateRound(
|
|
77
|
+
privateKey,
|
|
78
|
+
{
|
|
79
|
+
ethRegistryAddress,
|
|
80
|
+
ethTokenAddress,
|
|
81
|
+
web3Provider,
|
|
82
|
+
gas,
|
|
83
|
+
gasPrice,
|
|
84
|
+
transferRewardsToSolana,
|
|
85
|
+
}
|
|
86
|
+
) {
|
|
47
87
|
const web3 = new Web3(
|
|
48
88
|
new HDWalletProvider({
|
|
49
89
|
privateKeys: [privateKey],
|
|
@@ -52,18 +92,31 @@ async function initiateRound(privateKey, { ethRegistryAddress, ethTokenAddress,
|
|
|
52
92
|
)
|
|
53
93
|
|
|
54
94
|
web3.eth.transactionPollingTimeout = 3600
|
|
55
|
-
const accountAddress =
|
|
95
|
+
const accountAddress =
|
|
96
|
+
web3.eth.accounts.privateKeyToAccount(privateKey).address
|
|
56
97
|
|
|
57
|
-
const claimsManagerContract = await getClaimsManagerContract(
|
|
98
|
+
const claimsManagerContract = await getClaimsManagerContract(
|
|
99
|
+
ethRegistryAddress,
|
|
100
|
+
ethTokenAddress,
|
|
101
|
+
web3
|
|
102
|
+
)
|
|
58
103
|
|
|
59
|
-
const lastFundedBlock = await claimsManagerContract.methods
|
|
60
|
-
|
|
104
|
+
const lastFundedBlock = await claimsManagerContract.methods
|
|
105
|
+
.getLastFundedBlock()
|
|
106
|
+
.call()
|
|
107
|
+
const requiredBlockDiff = await claimsManagerContract.methods
|
|
108
|
+
.getFundingRoundBlockDiff()
|
|
109
|
+
.call()
|
|
61
110
|
|
|
62
111
|
const currentBlock = await web3.eth.getBlockNumber()
|
|
63
112
|
const blockDiff = currentBlock - lastFundedBlock - 12
|
|
64
113
|
|
|
65
114
|
if (blockDiff <= requiredBlockDiff) {
|
|
66
|
-
console.log(
|
|
115
|
+
console.log(
|
|
116
|
+
`Block difference of ${requiredBlockDiff} not met, ${
|
|
117
|
+
requiredBlockDiff - blockDiff
|
|
118
|
+
} blocks remaining`
|
|
119
|
+
)
|
|
67
120
|
process.exit(1)
|
|
68
121
|
}
|
|
69
122
|
|
|
@@ -76,12 +129,14 @@ async function initiateRound(privateKey, { ethRegistryAddress, ethTokenAddress,
|
|
|
76
129
|
console.log('Initializing Round')
|
|
77
130
|
await claimsManagerContract.methods.initiateRound().send({
|
|
78
131
|
from: accountAddress,
|
|
79
|
-
gas
|
|
132
|
+
gas,
|
|
80
133
|
})
|
|
81
134
|
console.log('Successfully initiated Round')
|
|
82
135
|
|
|
83
136
|
if (transferRewardsToSolana) {
|
|
84
|
-
const {
|
|
137
|
+
const {
|
|
138
|
+
transferCommunityRewardsToSolana,
|
|
139
|
+
} = require('@audius/sdk/scripts/communityRewards/transferCommunityRewardsToSolana')
|
|
85
140
|
console.log('Running rewards manager transfer')
|
|
86
141
|
await transferCommunityRewardsToSolana()
|
|
87
142
|
console.log('Successfully transferred rewards to solana')
|
|
@@ -101,29 +156,48 @@ async function claimRewards(
|
|
|
101
156
|
)
|
|
102
157
|
|
|
103
158
|
web3.eth.transactionPollingTimeout = 3600
|
|
104
|
-
const accountAddress =
|
|
159
|
+
const accountAddress =
|
|
160
|
+
web3.eth.accounts.privateKeyToAccount(privateKey).address
|
|
105
161
|
|
|
106
|
-
const claimsManagerContract = await getClaimsManagerContract(
|
|
107
|
-
|
|
162
|
+
const claimsManagerContract = await getClaimsManagerContract(
|
|
163
|
+
ethRegistryAddress,
|
|
164
|
+
ethTokenAddress,
|
|
165
|
+
web3
|
|
166
|
+
)
|
|
167
|
+
const delegateManagerContract = await getDelegateManagerContract(
|
|
168
|
+
ethRegistryAddress,
|
|
169
|
+
ethTokenAddress,
|
|
170
|
+
web3
|
|
171
|
+
)
|
|
108
172
|
|
|
109
|
-
const claimPending = await claimsManagerContract.methods
|
|
173
|
+
const claimPending = await claimsManagerContract.methods
|
|
174
|
+
.claimPending(spOwnerWallet)
|
|
175
|
+
.call()
|
|
110
176
|
|
|
111
177
|
if (claimPending) {
|
|
112
178
|
if (gas === undefined) {
|
|
113
179
|
console.log('Estimating Gas')
|
|
114
|
-
gas = await delegateManagerContract.methods
|
|
180
|
+
gas = await delegateManagerContract.methods
|
|
181
|
+
.claimRewards(spOwnerWallet)
|
|
182
|
+
.estimateGas()
|
|
115
183
|
console.log('Calculated Gas:', gas)
|
|
116
184
|
|
|
117
185
|
const gasPrice = await web3.eth.getGasPrice()
|
|
118
186
|
const estimatedFee = gas * gasPrice
|
|
119
|
-
console.log(
|
|
187
|
+
console.log(
|
|
188
|
+
'Estimated Fee:',
|
|
189
|
+
web3.utils.fromWei(estimatedFee.toString(), 'ether'),
|
|
190
|
+
'ETH'
|
|
191
|
+
)
|
|
120
192
|
}
|
|
121
193
|
|
|
122
194
|
console.log('Claiming Rewards')
|
|
123
195
|
await delegateManagerContract.methods.claimRewards(spOwnerWallet).send({
|
|
124
196
|
from: accountAddress,
|
|
125
197
|
gas,
|
|
126
|
-
gasPrice: gasPrice
|
|
198
|
+
gasPrice: gasPrice
|
|
199
|
+
? web3.utils.toWei(gasPrice, 'gwei')
|
|
200
|
+
: await web3.eth.getGasPrice(),
|
|
127
201
|
})
|
|
128
202
|
console.log('Claimed Rewards successfully')
|
|
129
203
|
} else {
|
|
@@ -135,20 +209,48 @@ async function main() {
|
|
|
135
209
|
program
|
|
136
210
|
.command('initiate-round <privateKey>')
|
|
137
211
|
.description('Initiates new round for claiming rewards')
|
|
138
|
-
.option(
|
|
139
|
-
|
|
140
|
-
|
|
212
|
+
.option(
|
|
213
|
+
'--eth-registry-address <ethRegistryAddress>',
|
|
214
|
+
'Registry contract address',
|
|
215
|
+
defaultRegistryAddress
|
|
216
|
+
)
|
|
217
|
+
.option(
|
|
218
|
+
'--eth-token-address <ethTokenAddress>',
|
|
219
|
+
'Token contract address',
|
|
220
|
+
defaultTokenAddress
|
|
221
|
+
)
|
|
222
|
+
.option(
|
|
223
|
+
'--web3-provider <web3Provider>',
|
|
224
|
+
'Web3 provider to use',
|
|
225
|
+
defaultWeb3Provider
|
|
226
|
+
)
|
|
141
227
|
.option('--gas <gas>', 'amount of gas to use')
|
|
142
228
|
.option('--gas-price <gasPrice>', 'gas price in gwei')
|
|
143
|
-
.option(
|
|
229
|
+
.option(
|
|
230
|
+
'--transfer-rewards-to-solana',
|
|
231
|
+
'whether to also transfer rewards to solana rewards manager on success. Requires env vars to be set.',
|
|
232
|
+
false
|
|
233
|
+
)
|
|
144
234
|
.action(initiateRound)
|
|
145
235
|
|
|
146
236
|
program
|
|
147
237
|
.command('claim-rewards <spOwnerWallet> <privateKey>')
|
|
148
238
|
.description('Claim rewards for given spOwnerWallet')
|
|
149
|
-
.option(
|
|
150
|
-
|
|
151
|
-
|
|
239
|
+
.option(
|
|
240
|
+
'--eth-registry-address <ethRegistryAddress>',
|
|
241
|
+
'Registry contract address',
|
|
242
|
+
defaultRegistryAddress
|
|
243
|
+
)
|
|
244
|
+
.option(
|
|
245
|
+
'--eth-token-address <ethTokenAddress>',
|
|
246
|
+
'Token contract address',
|
|
247
|
+
defaultTokenAddress
|
|
248
|
+
)
|
|
249
|
+
.option(
|
|
250
|
+
'--web3-provider <web3Provider>',
|
|
251
|
+
'Web3 provider to use',
|
|
252
|
+
defaultWeb3Provider
|
|
253
|
+
)
|
|
152
254
|
.option('--gas <gas>', 'ammount of gas to use')
|
|
153
255
|
.option('--gas-price <gasPrice>', 'gas price in gwei')
|
|
154
256
|
.action(claimRewards)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audius/sp-actions",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A utility for audius service providers to claim token rewards.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"claim": "claim.js"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"author": "Audius",
|
|
9
9
|
"license": "Apache-2.0",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@audius/sdk": "
|
|
11
|
+
"@audius/sdk": "6.0.0",
|
|
12
12
|
"@truffle/hdwallet-provider": "^1.2.2",
|
|
13
13
|
"axios": "^0.21.0",
|
|
14
14
|
"commander": "^6.2.1",
|