Skip to content

Commit

Permalink
Listener fixes (#254)
Browse files Browse the repository at this point in the history
* add ability to fund an account with OGV read from env variable

* fix deletion error, add extra fields to lockup table
  • Loading branch information
sparrowDom authored Jul 14, 2022
1 parent ce936b8 commit 0ba4908
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 7 deletions.
8 changes: 7 additions & 1 deletion client/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ const handleStake = async (event) => {
data: {
user: event.values.user,
lockupId: parseInt(event.values.lockupId),
amount: event.values.amount,
end: new Date(event.values.end * 1000),
points: event.values.points,
},
});
logger.info("Inserted lockup");
Expand All @@ -92,7 +95,10 @@ const handleUnstake = async (event) => {
try {
await prisma.lockup.delete({
where: {
lockupId: parseInt(event.values.lockupId),
lockupId_user: {
user: event.values.user,
lockupId: parseInt(event.values.lockupId),
}
},
});
logger.info("Removed lockup");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Warnings:
- A unique constraint covering the columns `[last_seen_block]` on the table `listener` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[lockupId,user]` on the table `lockups` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[proposal_id]` on the table `proposals` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[address]` on the table `voters` will be added. If there are existing duplicate values, this will fail.
- Added the required column `amount` to the `lockups` table without a default value. This is not possible if the table is not empty.
- Added the required column `end` to the `lockups` table without a default value. This is not possible if the table is not empty.
- Added the required column `points` to the `lockups` table without a default value. This is not possible if the table is not empty.
*/
-- DropIndex
DROP INDEX "listener_last_seen_block_key";

-- DropIndex
DROP INDEX "lockups_lockupId_user_key";

-- DropIndex
DROP INDEX "proposals_proposal_id_key";

-- DropIndex
DROP INDEX "voters_address_key";

-- AlterTable
ALTER TABLE "lockups" ADD COLUMN "amount" DECIMAL(78,0) NOT NULL,
ADD COLUMN "end" TIMESTAMP(3) NOT NULL,
ADD COLUMN "points" DECIMAL(78,0) NOT NULL;

-- CreateIndex
CREATE UNIQUE INDEX "listener_last_seen_block_key" ON "listener"("last_seen_block");

-- CreateIndex
CREATE UNIQUE INDEX "lockups_lockupId_user_key" ON "lockups"("lockupId", "user");

-- CreateIndex
CREATE UNIQUE INDEX "proposals_proposal_id_key" ON "proposals"("proposal_id");

-- CreateIndex
CREATE UNIQUE INDEX "voters_address_key" ON "voters"("address");
3 changes: 3 additions & 0 deletions client/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ model Lockup {
id Int @default(autoincrement()) @id
lockupId Int
user String
amount Decimal @db.Decimal(78, 0)
end DateTime
points Decimal @db.Decimal(78, 0)
createdAt DateTime @default(now()) @map("created_at")
@@unique([lockupId, user])
Expand Down
1 change: 1 addition & 0 deletions dev.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PROVIDER_URL=[SET PROVIDER URL HERE]
BLOCK_NUMBER=14171608
ACCOUNT_TO_FUND=[SET ACCOUNT TO FUND WITH OGV ON STARTUP]
6 changes: 5 additions & 1 deletion node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ main()
npm run generate-merkle-tree:dev

# deploy the contracts
npm run deploy:contracts:dev
if [ -z "$ACCOUNT_TO_FUND" ]; then
npm run deploy:contracts:dev
else
ACCOUNT_TO_FUND=${ACCOUNT_TO_FUND} npm run deploy:contracts:dev
fi

# wait for subprocesses to finish
for job in `jobs -p`
Expand Down
12 changes: 7 additions & 5 deletions scripts/deploy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from brownie import *
import os

EPOCH = 1657584000 # start of rewards: Tuesday, July 12, 2022 12:00:00 AM UTC
EST_EPOCH_BLOCK = 15124542
Expand Down Expand Up @@ -59,11 +60,12 @@ def main(
)

# if dev environment fund the contracts
if web3.chain_id == 31337 or web3.chain_id == 4:
token.transfer(
merkle_mandatory.address, 100000000 * 1e18, {"from": accounts[0]}
)
token.transfer(merkle_optional.address, 100000000 * 1e18, {"from": accounts[0]})
token.transfer(
merkle_mandatory.address, 100000000 * 1e18, {"from": accounts[0]}
)
token.transfer(merkle_optional.address, 100000000 * 1e18, {"from": accounts[0]})
if os.getenv('ACCOUNT_TO_FUND') is not None:
token.transfer(os.getenv('ACCOUNT_TO_FUND'), 100000000 * 1e18, {"from": accounts[0]})

# Make the governor the proposer and executor on timelock
timelock_controller.grantRole(web3.keccak(text="PROPOSER_ROLE"), governance)
Expand Down

0 comments on commit 0ba4908

Please sign in to comment.