Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
Add Pit file stability fee event
Browse files Browse the repository at this point in the history
- file event on the pit contract is overloaded and each implementation
  logs a note
- existing Pit file transformer now specified as dealing with ilks
  • Loading branch information
rmulhol committed Sep 5, 2018
1 parent 719d0f0 commit eb2b845
Show file tree
Hide file tree
Showing 31 changed files with 858 additions and 211 deletions.
3 changes: 2 additions & 1 deletion db/migrations/1535667935_create_pit_file_table.down.sql
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DROP TABLE maker.pit_file;
DROP TABLE maker.pit_file_ilk;
DROP TABLE maker.pit_file_stability_fee;
16 changes: 13 additions & 3 deletions db/migrations/1535667935_create_pit_file_table.up.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
CREATE TABLE maker.pit_file (
CREATE TABLE maker.pit_file_ilk (
id SERIAL PRIMARY KEY,
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
ilk TEXT,
what TEXT,
risk NUMERIC,
data NUMERIC,
tx_idx INTEGER NOT NUll,
raw_log JSONB,
UNIQUE (header_id, tx_idx)
);
);

CREATE TABLE maker.pit_file_stability_fee (
id SERIAL PRIMARY KEY,
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
what TEXT,
data TEXT,
tx_idx INTEGER NOT NULL,
raw_log JSONB,
UNIQUE (header_id, tx_idx)
)
101 changes: 83 additions & 18 deletions db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,25 @@ ALTER SEQUENCE maker.frob_id_seq OWNED BY maker.frob.id;


--
-- Name: pit_file; Type: TABLE; Schema: maker; Owner: -
-- Name: pit_file_ilk; Type: TABLE; Schema: maker; Owner: -
--

CREATE TABLE maker.pit_file (
CREATE TABLE maker.pit_file_ilk (
id integer NOT NULL,
header_id integer NOT NULL,
ilk text,
what text,
risk numeric,
data numeric,
tx_idx integer NOT NULL,
raw_log jsonb
);


--
-- Name: pit_file_id_seq; Type: SEQUENCE; Schema: maker; Owner: -
-- Name: pit_file_ilk_id_seq; Type: SEQUENCE; Schema: maker; Owner: -
--

CREATE SEQUENCE maker.pit_file_id_seq
CREATE SEQUENCE maker.pit_file_ilk_id_seq
AS integer
START WITH 1
INCREMENT BY 1
Expand All @@ -185,10 +185,44 @@ CREATE SEQUENCE maker.pit_file_id_seq


--
-- Name: pit_file_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: -
-- Name: pit_file_ilk_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: -
--

ALTER SEQUENCE maker.pit_file_id_seq OWNED BY maker.pit_file.id;
ALTER SEQUENCE maker.pit_file_ilk_id_seq OWNED BY maker.pit_file_ilk.id;


--
-- Name: pit_file_stability_fee; Type: TABLE; Schema: maker; Owner: -
--

CREATE TABLE maker.pit_file_stability_fee (
id integer NOT NULL,
header_id integer NOT NULL,
what text,
data text,
tx_idx integer NOT NULL,
raw_log jsonb
);


--
-- Name: pit_file_stability_fee_id_seq; Type: SEQUENCE; Schema: maker; Owner: -
--

CREATE SEQUENCE maker.pit_file_stability_fee_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- Name: pit_file_stability_fee_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: -
--

ALTER SEQUENCE maker.pit_file_stability_fee_id_seq OWNED BY maker.pit_file_stability_fee.id;


--
Expand Down Expand Up @@ -656,10 +690,17 @@ ALTER TABLE ONLY maker.frob ALTER COLUMN id SET DEFAULT nextval('maker.frob_id_s


--
-- Name: pit_file id; Type: DEFAULT; Schema: maker; Owner: -
-- Name: pit_file_ilk id; Type: DEFAULT; Schema: maker; Owner: -
--

ALTER TABLE ONLY maker.pit_file_ilk ALTER COLUMN id SET DEFAULT nextval('maker.pit_file_ilk_id_seq'::regclass);


--
-- Name: pit_file_stability_fee id; Type: DEFAULT; Schema: maker; Owner: -
--

ALTER TABLE ONLY maker.pit_file ALTER COLUMN id SET DEFAULT nextval('maker.pit_file_id_seq'::regclass);
ALTER TABLE ONLY maker.pit_file_stability_fee ALTER COLUMN id SET DEFAULT nextval('maker.pit_file_stability_fee_id_seq'::regclass);


--
Expand Down Expand Up @@ -788,19 +829,35 @@ ALTER TABLE ONLY maker.frob


--
-- Name: pit_file pit_file_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
-- Name: pit_file_ilk pit_file_ilk_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
--

ALTER TABLE ONLY maker.pit_file_ilk
ADD CONSTRAINT pit_file_ilk_header_id_tx_idx_key UNIQUE (header_id, tx_idx);


--
-- Name: pit_file_ilk pit_file_ilk_pkey; Type: CONSTRAINT; Schema: maker; Owner: -
--

ALTER TABLE ONLY maker.pit_file_ilk
ADD CONSTRAINT pit_file_ilk_pkey PRIMARY KEY (id);


--
-- Name: pit_file_stability_fee pit_file_stability_fee_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
--

ALTER TABLE ONLY maker.pit_file
ADD CONSTRAINT pit_file_header_id_tx_idx_key UNIQUE (header_id, tx_idx);
ALTER TABLE ONLY maker.pit_file_stability_fee
ADD CONSTRAINT pit_file_stability_fee_header_id_tx_idx_key UNIQUE (header_id, tx_idx);


--
-- Name: pit_file pit_file_pkey; Type: CONSTRAINT; Schema: maker; Owner: -
-- Name: pit_file_stability_fee pit_file_stability_fee_pkey; Type: CONSTRAINT; Schema: maker; Owner: -
--

ALTER TABLE ONLY maker.pit_file
ADD CONSTRAINT pit_file_pkey PRIMARY KEY (id);
ALTER TABLE ONLY maker.pit_file_stability_fee
ADD CONSTRAINT pit_file_stability_fee_pkey PRIMARY KEY (id);


--
Expand Down Expand Up @@ -999,11 +1056,19 @@ ALTER TABLE ONLY maker.price_feeds


--
-- Name: pit_file pit_file_header_id_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: -
-- Name: pit_file_ilk pit_file_ilk_header_id_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: -
--

ALTER TABLE ONLY maker.pit_file_ilk
ADD CONSTRAINT pit_file_ilk_header_id_fkey FOREIGN KEY (header_id) REFERENCES public.headers(id) ON DELETE CASCADE;


--
-- Name: pit_file_stability_fee pit_file_stability_fee_header_id_fkey; Type: FK CONSTRAINT; Schema: maker; Owner: -
--

ALTER TABLE ONLY maker.pit_file
ADD CONSTRAINT pit_file_header_id_fkey FOREIGN KEY (header_id) REFERENCES public.headers(id) ON DELETE CASCADE;
ALTER TABLE ONLY maker.pit_file_stability_fee
ADD CONSTRAINT pit_file_stability_fee_header_id_fkey FOREIGN KEY (header_id) REFERENCES public.headers(id) ON DELETE CASCADE;


--
Expand Down
2 changes: 1 addition & 1 deletion pkg/transformers/pit_file/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
var PitFileConfig = shared.TransformerConfig{
ContractAddress: "0xff3f2400f1600f3f493a9a92704a29b96795af1a", // temporary address from Ganache deploy
ContractAbi: shared.PitABI,
Topics: []string{shared.PitFileSignatureOne},
Topics: []string{shared.PitFileIlkSignature, shared.PitFileDebtCeilingSignature, shared.PitFileStabilityFeeSignature},
StartingBlockNumber: 0,
EndingBlockNumber: 100,
}
20 changes: 0 additions & 20 deletions pkg/transformers/pit_file/converter_test.go

This file was deleted.

13 changes: 13 additions & 0 deletions pkg/transformers/pit_file/debt_ceiling/debt_ceiling_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package debt_ceiling_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestDebtCeiling(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "DebtCeiling Suite")
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pit_file
package ilk

import (
"bytes"
Expand All @@ -8,24 +8,23 @@ import (
)

type Converter interface {
ToModel(contractAddress string, contractAbi string, ethLog types.Log) (PitFileModel, error)
ToModel(contractAddress string, contractAbi string, ethLog types.Log) (PitFileIlkModel, error)
}

type PitFileConverter struct {
}
type PitFileIlkConverter struct{}

func (PitFileConverter) ToModel(contractAddress string, contractAbi string, ethLog types.Log) (entity PitFileModel, err error) {
func (PitFileIlkConverter) ToModel(contractAddress string, contractAbi string, ethLog types.Log) (entity PitFileIlkModel, err error) {
ilk := string(bytes.Trim(ethLog.Topics[2].Bytes(), "\x00"))
what := string(bytes.Trim(ethLog.Topics[3].Bytes(), "\x00"))
itemByteLength := 32
riskBytes := ethLog.Data[len(ethLog.Data)-itemByteLength:]
risk := big.NewInt(0).SetBytes(riskBytes).String()

raw, err := json.Marshal(ethLog)
return PitFileModel{
return PitFileIlkModel{
Ilk: ilk,
What: what,
Risk: risk,
Data: risk,
TransactionIndex: ethLog.TxIndex,
Raw: raw,
}, err
Expand Down
20 changes: 20 additions & 0 deletions pkg/transformers/pit_file/ilk/converter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ilk_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
)

var _ = Describe("Pit file ilk converter", func() {
It("converts a log to an model", func() {
converter := ilk.PitFileIlkConverter{}

model, err := converter.ToModel(test_data.PitAddress, shared.PitABI, test_data.EthPitFileIlkLog)

Expect(err).NotTo(HaveOccurred())
Expect(model).To(Equal(test_data.PitFileIlkModel))
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pit_file_test
package ilk_test

import (
"testing"
Expand All @@ -7,7 +7,7 @@ import (
. "github.com/onsi/gomega"
)

func TestPitFile(t *testing.T) {
func TestIlk(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "PitFile Suite")
RunSpecs(t, "Ilk Suite")
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package pit_file
package ilk

type PitFileModel struct {
type PitFileIlkModel struct {
Ilk string
What string
Risk string
Data string
TransactionIndex uint `db:"tx_idx"`
Raw []byte `db:"raw_log"`
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
package pit_file
package ilk

import (
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
)

type Repository interface {
Create(headerID int64, transactionIndex uint, model PitFileModel) error
Create(headerID int64, model PitFileIlkModel) error
MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error)
}

type PitFileRepository struct {
type PitFileIlkRepository struct {
db *postgres.DB
}

func NewPitFileRepository(db *postgres.DB) PitFileRepository {
return PitFileRepository{
func NewPitFileIlkRepository(db *postgres.DB) PitFileIlkRepository {
return PitFileIlkRepository{
db: db,
}
}

func (repository PitFileRepository) Create(headerID int64, transactionIndex uint, model PitFileModel) error {
func (repository PitFileIlkRepository) Create(headerID int64, model PitFileIlkModel) error {
_, err := repository.db.Exec(
`INSERT into maker.pit_file (header_id, ilk, what, risk, tx_idx, raw_log)
`INSERT into maker.pit_file_ilk (header_id, ilk, what, data, tx_idx, raw_log)
VALUES($1, $2, $3, $4::NUMERIC, $5, $6)`,
headerID, model.Ilk, model.What, model.Risk, model.TransactionIndex, model.Raw,
headerID, model.Ilk, model.What, model.Data, model.TransactionIndex, model.Raw,
)
return err
}

func (repository PitFileRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
func (repository PitFileIlkRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header
err := repository.db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
LEFT JOIN maker.pit_file on headers.id = header_id
LEFT JOIN maker.pit_file_ilk on headers.id = header_id
WHERE header_id ISNULL
AND headers.block_number >= $1
AND headers.block_number <= $2
Expand Down
Loading

0 comments on commit eb2b845

Please sign in to comment.