Skip to content

Commit 6be83c1

Browse files
committed
Tested the new staking functions, all work on subgraph now
1 parent 70b61ee commit 6be83c1

File tree

6 files changed

+168
-28
lines changed

6 files changed

+168
-28
lines changed

scripts/cli/commands/protocol.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ const gettersList = {
2222
'staking-thawing-period': { contract: 'Staking', name: 'thawingPeriod' },
2323
'staking-dispute-epochs': { contract: 'Staking', name: 'channelDisputeEpochs' },
2424
'staking-max-allocation-epochs': { contract: 'Staking', name: 'maxAllocationEpochs' },
25+
'staking-delegation-capacity': { contract: 'Staking', name: 'delegationCapacity' },
26+
'staking-delegation-parameters-cooldown': {
27+
contract: 'Staking',
28+
name: 'delegationParametersCooldown',
29+
},
30+
'staking-delegation-unbonding-period': { contract: 'Staking', name: 'delegationUnbondingPeriod' },
2531
'protocol-percentage': { contract: 'Staking', name: 'protocolPercentage' },
2632
'curation-governor': { contract: 'Curation', name: 'governor' },
2733
'curation-staking-contract': { contract: 'Curation', name: 'staking' },
@@ -51,6 +57,15 @@ const settersList = {
5157
'staking-dispute-epochs': { contract: 'Staking', name: 'setChannelDisputeEpochs' },
5258
'staking-max-allocation-epochs': { contract: 'Staking', name: 'setMaxAllocationEpochs' },
5359
'staking-protocol-percentage': { contract: 'Staking', name: 'setProtocolPercentage' },
60+
'staking-delegation-capacity': { contract: 'Staking', name: 'setDelegationCapacity' },
61+
'staking-delegation-parameters-cooldown': {
62+
contract: 'Staking',
63+
name: 'setDelegationParametersCooldown',
64+
},
65+
'staking-delegation-unbonding-period': {
66+
contract: 'Staking',
67+
name: 'setDelegationUnbondingPeriod',
68+
},
5469
'curation-governor': { contract: 'Curation', name: 'setGovernor' },
5570
'curation-staking-contract': { contract: 'Curation', name: 'setStaking' },
5671
'curation-reserve-ratio': { contract: 'Curation', name: 'setDefaultReserveRatio' },

scripts/contracts/connectedContracts.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,11 @@ class ConnectedStaking extends ConnectedContract {
334334
}
335335

336336
allocateWithDecimals = async (
337-
amount: string,
338-
price: string,
339-
channelProxy: string,
340337
subgraphDeploymentID: string,
338+
amount: string,
341339
channelPubKey: string,
340+
channelProxy: string,
341+
price: string,
342342
): Promise<ContractTransaction> => {
343343
const amountParseDecimals = utils.parseUnits(amount as string, 18).toString()
344344
return this.contract.allocate(
@@ -347,6 +347,7 @@ class ConnectedStaking extends ConnectedContract {
347347
channelPubKey,
348348
channelProxy,
349349
price,
350+
basicOverrides(),
350351
)
351352
}
352353

scripts/contracts/helpers.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,56 @@ export const mockChannelPubKeys: Array<string> = [
202202
'0x0456708870bfd5d8fc956fe33285dcf59b075cd7a25a21ee00834e480d3754bcda180e670145a290bb4bebca8e105ea7776a7b39e16c4df7d4d1083260c6f05d58',
203203
'0x0456708870bfd5d8fc956fe33285dcf59b075cd7a25a21ee00834e480d3754bcda180e670145a290bb4bebca8e105ea7776a7b39e16c4df7d4d1083260c6f05d59',
204204
]
205+
206+
// User accounts used are always 0 to 10
207+
export const userAccounts = (mnemonic: string, provider: string): Array<Wallet> => {
208+
return configureWallets(mnemonic, provider, 10)
209+
}
210+
211+
/* Proxy accounts used are always 10 to 20.
212+
Addresses below:
213+
0x853d474EB22701b94910f275CdB57A62c4B2db7E
214+
0x2A7f74f2F90d34eceE06E6196D3da7B8FcA02fa2
215+
0x048CdeADbcb9E493D19b48eB7B693DC056Fd2036
216+
0xD03a084A951B42bEb1a30232B8f738AB288256fa
217+
0xEF99F3f68Dc194a3720b374c2e3AC56beF8d8D61
218+
0x1A8f34607F6495f7E3bF6ee7553C12602B826D7A
219+
0xEAaeC61E782992f85cCc096a16Fc9C74EfaA5355
220+
0xf7c0e78323Fcb0532cEa23d99B63C729e178568A
221+
0xF6cAdFc68B855e2944f27C5DF4a66c52B24d2d94
222+
0x4cc6B907c7Bf1480426075e832Dc35bBC7264077
223+
*/
224+
export const proxyAccounts = (mnemonic: string, provider: string): Array<Wallet> => {
225+
const wallets = configureWallets(mnemonic, provider, 20)
226+
return wallets.slice(10, 20)
227+
}
228+
229+
/* Channel accounts used are always 20 to 30.
230+
Addresses below:
231+
0x73f0bd80493BEA09BAFAFCdc6E71A9569eAcA0aB
232+
0xeD12E3068Cdb1F9afD7A038c5a7B1a9b66C5986B
233+
0x3796d3711070222d49EE6207Fe1cd4b2fcAD0663
234+
0xfBD176446f56c0a52f44c5bfC24d339fF4B09470
235+
0xbe45140e5783c8F5fA5123fDcC74D209f3c9155b
236+
0x2084259748B13F800B6aE0b7A33c87e49546BfD8
237+
0x81A90593786e6d0fC9cF29C9842Bca4Ab2f1bEb7
238+
0xA3e182b8CaC70b43c84a437a4F1774447505EA40
239+
0x082b1536F8C9b0Ca3198a911c4934e456C2f7c32
240+
0xBA6D2612dEA713e61a7c22E691af4eaea46aCf75
241+
242+
Uncompressed public keys below:
243+
0x04e8c44ab3118e5ca2e470ff20556bb6b470a5265ca0992e82e9a26cf332d87cf6e3add759bd4ed23277fadc46dd9b79fbcce33314cb4a48687830f6a524ebb998
244+
0x04c10f828e7ee0cc03dfed95bb8497de9d5366c6b13d9524ef8bcabdd5b1f58f1a38de3332e16a124da62ac298ed1cbfc6d867576635a0151c55ac3d9c84778f1c
245+
0x04d51dc84783a733fbe1ab91255d8fcd0195c8a03937dd6791426142de8e8da6eb5519cab9730648e3c3dac51bc0865347d80860b7c707944a051e0896cbc7b632
246+
0x04dc700c3efcb80c151de25ae5ffa417f2556b5b3a0c9edba771febfdd9f8ea82943f62709942ea23185771b96c976cbb709e307130b4ea343b1888ef200166cce
247+
0x04185736d5509a687f0b64dd5caf4497443650d67708138daff1ccf3aa900d936cd399a25a58951f3801dfb61f81d48b396e49296bcac67ca35aed5e65fd5e65ed
248+
0x04f4fd3d15f633540db5fd5f69f3a83b5f9a43b258c0855e8f87dd586e9fd33fb06d72fbfad9fd90c1fd59eccf6589099403583cfb89604eb1b0eb472e61f5fefe
249+
0x04a880416006af0996a76e1b5d6171c005009d55bd7af8ed78b2af6bfbfafdff755c68f0e32e49ca0627acceec1611d5521dde7b90076c4ba1894e3dfb53c01ffd
250+
0x047da2b532a32e1f87b570a4675e71fa9a794c43cda4562d1e9c55975534b335f00c8ac1006b7b303d4e72189af7caa70112eff9b47bfe00e37b4d832fcc716b50
251+
0x04cc3c74d466211b119217e97806f8ec5f09d865940c99effaae967dc67e282ff09aa1900fdb14865f8e3323cac75d6f193fa85b5c732b742163d1d83d699c04a3
252+
0x04c9558bb809ed4c65cce849db4337c29b6c72bec97bb6a600a8af7fc72ded8486ae3a76916e424c9cef6e40721f9c8b265056862897afad7cc859b8e34d4dbc95
253+
*/
254+
export const channelAccounts = (mnemonic: string, provider: string): Array<Wallet> => {
255+
const wallets = configureWallets(mnemonic, provider, 30)
256+
return wallets.slice(20, 30)
257+
}

scripts/contracts/populateData.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import { AccountMetadata, SubgraphMetadata } from '../metadataHelpers'
1717
import * as AccountDatas from '../mockData/account-metadata/accountMetadatas'
1818
import * as SubgraphDatas from '../mockData/subgraph-metadata/subgraphMetadatas'
1919
import {
20-
configureWallets,
20+
userAccounts,
21+
proxyAccounts,
22+
channelAccounts,
2123
executeTransaction,
2224
checkGovernor,
2325
mockChannelPubKeys,
@@ -331,18 +333,18 @@ const populateStaking = async (network: string, signers: Array<Wallet>, proxies:
331333
}
332334

333335
const populateAll = async (mnemonic: string, provider: string, network: string): Promise<void> => {
334-
const signers = configureWallets(mnemonic, provider, 20)
335-
const userAccounts = signers.slice(0, 10)
336-
const proxyAccounts = signers.slice(10, 20)
336+
const users = userAccounts(mnemonic, provider)
337+
const proxies = proxyAccounts(mnemonic, provider)
338+
const channels = channelAccounts(mnemonic, provider)
337339
const governor = signers[0]
338340
// await sendEth(network, governor, userAccounts, proxyAccounts, '0.25') // only use at the start. TODO - make this a cli option or something
339-
await populateGraphToken(network, userAccounts, proxyAccounts, '100000') // only use at the start. TODO - make this a cli option or something
340-
await populateEthereumDIDRegistry(network, userAccounts)
341-
await populateENS(network, userAccounts)
342-
await populateGNS(network, userAccounts)
343-
await populateCuration(network, userAccounts)
344-
await populateServiceRegistry(network, userAccounts)
345-
await populateStaking(network, userAccounts, proxyAccounts)
341+
await populateGraphToken(network, users, proxies, '100000') // only use at the start. TODO - make this a cli option or something
342+
await populateEthereumDIDRegistry(network, users)
343+
await populateENS(network, users)
344+
await populateGNS(network, users)
345+
await populateCuration(network, users)
346+
await populateServiceRegistry(network, users)
347+
await populateStaking(network, users, proxies)
346348
}
347349

348350
export default populateAll

scripts/contracts/staking.ts

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
buildNetworkEndpoint,
1111
} from './helpers'
1212
import { ConnectedStaking, ConnectedGraphToken } from './connectedContracts'
13+
import { utils, BigNumber } from 'ethers'
1314

1415
const {
1516
network,
@@ -19,6 +20,10 @@ const {
1920
channelPubKey,
2021
channelProxy,
2122
price,
23+
channelID,
24+
restake,
25+
indexer,
26+
newIndexer,
2227
} = minimist.default(process.argv.slice(2), {
2328
string: [
2429
'network',
@@ -28,6 +33,10 @@ const {
2833
'channelPubKey',
2934
'channelProxy',
3035
'price',
36+
'channelID',
37+
'restake',
38+
'indexer',
39+
'newIndexer',
3140
],
3241
})
3342

@@ -37,7 +46,8 @@ if (!network || !func) {
3746
Usage: ${path.basename(process.argv[1])}
3847
--network <string> - options: ganache, kovan, rinkeby
3948
40-
--func <text> - options: stake, unstake, withdraw, allocate, settle
49+
--func <text> - options: stake, unstake, withdraw, allocate, settle, collect, claim, delegate
50+
undelegate, withdrawDelegated
4151
4252
Function arguments:
4353
stake
@@ -52,12 +62,33 @@ Usage: ${path.basename(process.argv[1])}
5262
allocate
5363
--subgraphDeploymentID <bytes32> - The subgraph deployment ID being allocated on
5464
--amount <number> - Amount of tokens being allocated (script adds 10^18)
55-
--channelPubKey <bytes> - The subgraph deployment ID being allocated on
56-
--channelProxy <address> - The subgraph deployment ID being allocated on
65+
--channelPubKey <bytes> - The public key used by the indexer to setup the off-chain channel
66+
--channelProxy <address> - Address of the multisig proxy used to hold channel funds
5767
--price <number> - Price the indexer will charge for serving queries of the subgraphID
5868
59-
settle (Note - settle must be called by the channelProxy that created the allocation)
60-
--amount <number> - Amount of tokens being settled (script adds 10^18)
69+
settle (note - must pass at least one epoch)
70+
--channelID <number> - Channel being settled
71+
72+
collect (Note - collect must be called by the channelProxy)
73+
--channelID - ID of the channel we are collecting funds from
74+
--from - Multisig channel address that triggered the withdrawal
75+
--amount - Token amount to withdraw
76+
77+
claim (note - you must have settled the channel already)
78+
--channelID - ID of the channel we are claiming funds from
79+
--restake - True if you are restaking the fees, rather than withdrawing
80+
81+
delegate
82+
--indexer - Indexer being delegated to
83+
--amount - Amount of tokens being delegated (automatically adds 10^18)
84+
85+
undelegate
86+
--indexer - Indexer being delegated to
87+
--amount - Amount of shares being undelegated
88+
89+
withdrawDelegated
90+
--indexer - Indexer being withdrawn from
91+
--newIndexer - Indexer being delegated to
6192
`,
6293
)
6394
process.exit(1)
@@ -79,7 +110,7 @@ const main = async () => {
79110

80111
try {
81112
if (func == 'stake') {
82-
checkFuncInputs([amount], ['amount'], 'stake')
113+
checkFuncInputs([amount], ['amount'], func)
83114
console.log(' First calling approve() to ensure staking contract can call transferFrom()...')
84115
await executeTransaction(
85116
connectedGT.approveWithDecimals(staking.contract.address, amount),
@@ -88,30 +119,66 @@ const main = async () => {
88119
console.log(`Staking ${amount} tokens in the staking contract...`)
89120
await executeTransaction(staking.stakeWithDecimals(amount), network)
90121
} else if (func == 'unstake') {
91-
checkFuncInputs([amount], ['amount'], 'unstake')
122+
checkFuncInputs([amount], ['amount'], func)
92123
console.log(`Unstaking ${amount} tokens. Tokens will be locked...`)
93124
await executeTransaction(staking.unstakeWithDecimals(amount), network)
94125
} else if (func == 'withdraw') {
95126
console.log(`Unlock tokens and withdraw them from the staking contract...`)
96127
await executeTransaction(staking.contract.withdraw(), network)
97128
} else if (func == 'allocate') {
98-
checkFuncInputs([amount, price], ['amount', 'price'], 'allocate')
129+
checkFuncInputs([amount, price], ['amount', 'price'], func)
99130
console.log(`Allocating ${amount} tokens on state channel ${subgraphDeploymentID} ...`)
100131
await executeTransaction(
101132
staking.allocateWithDecimals(
102-
amount,
103-
price,
104133
subgraphDeploymentID,
134+
amount,
105135
channelPubKey,
106136
channelProxy,
137+
price,
107138
),
108139
network,
109140
)
110141
} else if (func == 'settle') {
111-
// Note - this function must be called by the channel proxy eth address
112-
checkFuncInputs([amount], ['amount'], 'settle')
113-
console.log(`Settling ${amount} tokens on state channel with proxy address TODO`)
114-
await executeTransaction(staking.settleWithDecimals(amount), network)
142+
checkFuncInputs([channelID], ['channelID'], func)
143+
console.log(`Settling channel: ${channelID}...`)
144+
await executeTransaction(staking.contract.settle(channelID), network)
145+
} else if (func == 'collect') {
146+
console.log('COLLECT NOT IMPLEMENTED. NORMALLY CALLED FROM PROXY ACCOUNT')
147+
process.exit(1)
148+
} else if (func == 'claim') {
149+
checkFuncInputs([channelID, restake], ['channelID', 'restake'], func)
150+
console.log(`Claiming channel: ${channelID}...`)
151+
await executeTransaction(staking.contract.claim(channelID, restake), network)
152+
} else if (func == 'delegate') {
153+
checkFuncInputs([amount, indexer], ['amount', 'indexer'], func)
154+
console.log(' First calling approve() to ensure staking contract can call transferFrom()...')
155+
await executeTransaction(
156+
connectedGT.approveWithDecimals(staking.contract.address, amount),
157+
network,
158+
)
159+
console.log(`Delegating ${amount} tokens to indexer: ${indexer}...`)
160+
const amountParseDecimals = utils.parseUnits(amount as string, 18)
161+
await executeTransaction(staking.contract.delegate(indexer, amountParseDecimals), network)
162+
} else if (func == 'undelegate') {
163+
checkFuncInputs([amount, indexer], ['amount', 'indexer'], func)
164+
console.log(`Undelegating ${amount} shares from indexer: ${indexer}...`)
165+
const amountParseDecimals = utils.parseUnits(amount as string, 18)
166+
await executeTransaction(staking.contract.undelegate(indexer, amountParseDecimals), network)
167+
} else if (func == 'withdrawDelegated') {
168+
checkFuncInputs([newIndexer, indexer], ['newIndexer', 'indexer'], func)
169+
console.log(`Withdrawing from ${indexer}`)
170+
if (newIndexer != '0x0000000000000000000000000000000000000000') {
171+
console.log(`Depositing to : ${newIndexer}...`)
172+
}
173+
await executeTransaction(staking.contract.withdrawDelegated(indexer, newIndexer), network)
174+
} else if (func == 'getDelegationShares') {
175+
checkFuncInputs([indexer], ['indexer'], func)
176+
console.log(`Getting delegation shares....`)
177+
const shares = await staking.contract.getDelegationShares(
178+
indexer,
179+
staking.configuredWallet.address,
180+
)
181+
console.log(shares.div(BigNumber.from('1000000000000000000')).toString())
115182
} else {
116183
console.log(`Wrong func name provided`)
117184
process.exit(1)

scripts/teamAddresses.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type TeamAddresses = {
99
ariel: string
1010
dave: string
1111
zac: string
12+
martin: string
1213
}
1314

1415
export const teamAddresses: TeamAddresses = {
@@ -22,4 +23,5 @@ export const teamAddresses: TeamAddresses = {
2223
ariel: '0xeF38F892E4722152fD8eDb50cD84a96344FD47Ce',
2324
dave: '0x93606b27cB5e4c780883eC4F6b7Bed5f6572d1dd',
2425
zac: '0xD31bC1e2a214066Bb2258dac5f43Ce75e5542Ab9',
26+
martin: '0x055BCF2c2BC965Ac8EEAe3f95922D65EE45d3366',
2527
}

0 commit comments

Comments
 (0)