aragon / court-subgraph

Aragon Court subgraph
GNU General Public License v3.0
13 stars 7 forks source link

New subscription fees #73

Closed bingen closed 4 years ago

bingen commented 4 years ago

To test this PR:

Follow the instructions here to deploy a subgraph locally. Make sure to change the Subscriptios periodDuration in the deploy config file to a small value, for instance 1.

Go to aragon-court repo and open a console with truffle console --network rpc, but first make sure you have MiniMe token handy, for instance by doing:

cp ../aragon-apps/apps/agreement/build/contracts/MiniMeToken.json build/contracts

Also make sure you are in master branch, to have the old version, and just in case:

rm -Rf build/contracts
truffle compile

In the console run the following commands to feed some data to the old subscriptions module:

const bn = x => new web3.utils.BN(x)
const toWei = x => web3.utils.toWei(x.toString(), 'ether')

const accounts = await web3.eth.getAccounts()
const from = (await web3.eth.getAccounts())[0]

const ANJ = await MiniMeToken.at('0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B')
const DAI = await MiniMeToken.at('0x5b1869D9A4C187F2EAa108f3062412ecf0526b24')
await ANJ.generateTokens(from, web3.utils.toWei('10000', 'ether'))
await DAI.generateTokens(from, web3.utils.toWei('1000000', 'ether'))

const court = await AragonCourt.at('0xC89Ce4735882C9F0f0FE26686c53074E09B0D550')
await court.heartbeat('10')

const registry = await JurorsRegistry.at('0x9561C133DD8580860B6b7E504bC5Aa500f0f06a7')
const stakeAmount = web3.utils.toWei('100', 'ether')
await ANJ.approve(registry.address, stakeAmount)
await registry.stake(stakeAmount, '0x00')
await registry.activate(stakeAmount)

const oldSubscriptions = await CourtSubscriptions.at('0x0290FB167208Af455bB137780163b7B7a9a10C16')

const donation = web3.utils.toWei('100', 'ether')
await DAI.approve(oldSubscriptions.address, bn(donation).mul(bn(10)))
await oldSubscriptions.donate(donation)

let currentPeriodId = await oldSubscriptions.getCurrentPeriodId()
currentPeriodId.toString()
await oldSubscriptions.getJurorShare(from, '1') // change it to the corresponding periodId
await oldSubscriptions.claimFees('1') // change it to the corresponding periodId

Make sure you let some time go by to increase the periods, and keep running the heartbeats. Then you can repeat the donations and claims.

Now close the console and get the new Subscriptions module:

git checkout development
rm -Rf build/contracts
truffle compile

Open the console again and run:

const bn = x => new web3.utils.BN(x)
const toWei = x => web3.utils.toWei(x.toString(), 'ether')
const DAI = await MiniMeToken.at('0x5b1869D9A4C187F2EAa108f3062412ecf0526b24')

const newSubscriptions = await CourtSubscriptions.new(court.address, 1, DAI.address, '10000000000000000000', 0)
//const newSubscriptions = await CourtSubscriptions.at('0xA586074FA4Fe3E546A132a16238abe37951D41fE')
await court.setModule('0x2bfa3327fe52344390da94c32a346eeb1b65a8b583e4335a419b9471e88c1365', newSubscriptions.address)

await DAI.approve(newSubscriptions.address, bn(donation).mul(bn(10)))
await newSubscriptions.donate(donation)

await newSubscriptions.claimFees('37') // change it to the corresponding periodId

let setR = await newSubscriptions.setAppFee('0x1234', DAI.address, toWei(11))
let payR = await newSubscriptions.payAppFees('0x1234', '0x00')
let unsetR = await newSubscriptions.unsetAppFee('0x1234')

Again, you can do several donations and AppFee payments.

Finally, go to the Graph dashboard and check that everything matches with this query:

{
  subscriptionModules(first: 5) {
    id,
    court {
      id,
      currentTerm,
      terms(first: 2, orderBy: startTime, orderDirection: desc) {
        id
        startTime
        randomnessBN
        randomness
        createdAt
      }
    }
    currentPeriod
    periods(orderBy: createdAt, orderDirection: desc) {
      id
      instance {
        id
      }
      accumulatedGovernorFees
      collectedFees
      jurorClaims(orderBy: id) {
        id
        period {
          id
        }
        juror {
          id
        }
        amount
      }
    }
    appFees {
      id
      isSet
      amount
    }
    tokens {
      id
      totalPaid
      totalDonated
      totalAppPaid
      totalCollected
      totalGovernorShares
    }
  }
}
facuspagnuolo commented 4 years ago

@sohkai thx for reviewing! I addressed your suggestions, let me know your thoughts!