-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
3,188 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class MerkleDistributorRecipient1667312452969 implements MigrationInterface { | ||
name = "MerkleDistributorRecipient1667312452969"; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
ALTER TABLE "merkle_distributor_recipient" | ||
DROP CONSTRAINT "UK_merkle_distributor_recipient_merkleDistributorWindowId_addre" | ||
`); | ||
await queryRunner.query(` | ||
ALTER TABLE "merkle_distributor_recipient" | ||
ADD CONSTRAINT "UK_merkle_distributor_recipient_windowId_address" | ||
UNIQUE ("merkleDistributorWindowId", "address") | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
ALTER TABLE "merkle_distributor_recipient" | ||
DROP CONSTRAINT "UK_merkle_distributor_recipient_windowId_address" | ||
`); | ||
await queryRunner.query(` | ||
ALTER TABLE "merkle_distributor_recipient" | ||
ADD CONSTRAINT "UK_merkle_distributor_recipient_merkleDistributorWindowId_addre" | ||
UNIQUE ("merkleDistributorWindowId", "address") | ||
`); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
migrations/1667813310964-MerkleDistributorProcessedBlock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class MerkleDistributorProcessedBlock1667813310964 implements MigrationInterface { | ||
name = "MerkleDistributorProcessedBlock1667813310964"; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
CREATE TABLE "merkle_distributor_processed_block" ( | ||
"id" SERIAL NOT NULL, | ||
"chainId" integer NOT NULL, | ||
"latestBlock" integer NOT NULL, | ||
"createdAt" TIMESTAMP NOT NULL DEFAULT now(), | ||
CONSTRAINT "PK_fb2eb512abaadb453e1cfef109e" PRIMARY KEY ("id")) | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP TABLE "merkle_distributor_processed_block"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class Claim1667813310965 implements MigrationInterface { | ||
name = "Claim1667813310965"; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
CREATE TABLE "claim" ( | ||
"id" SERIAL NOT NULL, | ||
"caller" character varying NOT NULL, | ||
"accountIndex" integer NOT NULL, | ||
"windowIndex" integer NOT NULL, | ||
"account" character varying NOT NULL, | ||
"rewardToken" character varying NOT NULL, | ||
"blockNumber" integer NOT NULL, | ||
"claimedAt" TIMESTAMP NOT NULL, | ||
"createdAt" TIMESTAMP NOT NULL DEFAULT now(), | ||
"updatedAt" TIMESTAMP NOT NULL DEFAULT now(), | ||
"merkleDistributorWindowId" integer, | ||
CONSTRAINT "UK_claim_windowIndex_accountIndex" UNIQUE ( | ||
"windowIndex", | ||
"accountIndex" | ||
), | ||
CONSTRAINT "PK_466b305cc2e591047fa1ce58f81" PRIMARY KEY ("id")) | ||
`); | ||
await queryRunner.query(`CREATE INDEX "IX_claim_account" ON "claim" ("account")`); | ||
await queryRunner.query(` | ||
ALTER TABLE "claim" | ||
ADD CONSTRAINT "FK_169ca2a2e031f01f62d81dbf1a0" | ||
FOREIGN KEY ("merkleDistributorWindowId") | ||
REFERENCES "merkle_distributor_window"("id") | ||
ON DELETE NO ACTION ON UPDATE NO ACTION | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
ALTER TABLE "claim" DROP CONSTRAINT "FK_169ca2a2e031f01f62d81dbf1a0" | ||
`); | ||
await queryRunner.query(`DROP TABLE "merkle_distributor_processed_block"`); | ||
await queryRunner.query(`DROP INDEX "public"."IX_claim_account"`); | ||
await queryRunner.query(`DROP TABLE "claim"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class Deposit1667822226389 implements MigrationInterface { | ||
name = "Deposit1667822226389"; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "deposit" ADD "rewardsWindowIndex" integer`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "deposit" DROP COLUMN "rewardsWindowIndex"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class DepositsMaterializedView1668007817974 implements MigrationInterface { | ||
name = "DepositsMaterializedView1668007817974"; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP MATERIALIZED VIEW IF EXISTS "deposits_mv"`); | ||
await queryRunner.query(`DROP VIEW IF EXISTS "deposit_referral_stats"`); | ||
await queryRunner.query(`DROP VIEW IF EXISTS "deposits_filtered_referrals"`); | ||
await queryRunner.query(`CREATE VIEW "deposits_filtered_referrals" AS | ||
SELECT | ||
d.id, | ||
d."stickyReferralAddress", | ||
d."depositDate", | ||
d."priceId", | ||
d."tokenId", | ||
d.amount, | ||
d."depositorAddr", | ||
case when d."rewardsWindowIndex" = c."windowIndex" then d."rewardsWindowIndex" else -1 end as "claimedWindowIndex", | ||
hmp."usd", | ||
t.decimals | ||
FROM deposit d | ||
JOIN historic_market_price hmp on d."priceId" = hmp.id | ||
JOIN token t on d."tokenId" = t.id | ||
LEFT JOIN claim c on d."rewardsWindowIndex" = c."windowIndex" and d."referralAddress" = c."account" | ||
WHERE "stickyReferralAddress" is not null | ||
AND "depositDate" is not null | ||
AND "tokenId" is not null | ||
AND "priceId" is not null | ||
AND status = 'filled'; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP MATERIALIZED VIEW "deposits_mv"`); | ||
await queryRunner.query(`DROP VIEW "deposit_referral_stats"`); | ||
await queryRunner.query(`DROP VIEW "deposits_filtered_referrals"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class DepositReferralStat1668339782207 implements MigrationInterface { | ||
name = "DepositReferralStat1668339782207"; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TABLE "deposit_referral_stat" ( | ||
"id" SERIAL NOT NULL, | ||
"depositId" integer NOT NULL, | ||
"referralCount" integer NOT NULL, | ||
"referralVolume" numeric NOT NULL, | ||
"createdAt" TIMESTAMP NOT NULL DEFAULT now(), | ||
"updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_74ce2ecc7d76a2e59039e94fcfc" PRIMARY KEY ("id") | ||
)`, | ||
); | ||
await queryRunner.query(`CREATE UNIQUE INDEX "UK_drs_depositId" ON deposit_referral_stat ("depositId");`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP TABLE "deposit_referral_stat"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class DepositsMaterializedView1668339782208 implements MigrationInterface { | ||
name = "DepositsMaterializedView1668339782208"; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP MATERIALIZED VIEW IF EXISTS "deposits_mv"`); | ||
await queryRunner.query(`CREATE MATERIALIZED VIEW "deposits_mv" AS | ||
SELECT | ||
d.id, | ||
d."depositId", | ||
d."depositTxHash", | ||
d."sourceChainId", | ||
d."destinationChainId", | ||
d.amount, | ||
t.symbol, | ||
t.decimals, | ||
d."depositorAddr", | ||
d."rewardsWindowIndex", | ||
case when d."rewardsWindowIndex" = c."windowIndex" and d."depositorAddr" = c.account then d."rewardsWindowIndex" else -1 end as "depositorClaimedWindowIndex", | ||
case when d."rewardsWindowIndex" = c."windowIndex" and d."stickyReferralAddress" = c.account then d."rewardsWindowIndex" else -1 end as "referralClaimedWindowIndex", | ||
d."stickyReferralAddress" AS "referralAddress", | ||
d."depositDate", | ||
hmp.usd AS "tokenUsdPrice", | ||
(d."realizedLpFeePctCapped" / power(10, 18)) * (d.amount / power(10, t.decimals)) * hmp.usd AS "realizedLpFeeUsd", | ||
(d."bridgeFeePct" / power(10, 18)) * (d.amount / power(10, t.decimals)) * hmp.usd AS "bridgeFeeUsd", | ||
CASE | ||
WHEN d1."referralCount" >= 20 OR d1."referralVolume" >= 500000 THEN 0.8 | ||
WHEN d1."referralCount" >= 10 OR d1."referralVolume" >= 250000 THEN 0.7 | ||
WHEN d1."referralCount" >= 5 OR d1."referralVolume" >= 100000 THEN 0.6 | ||
WHEN d1."referralCount" >= 3 OR d1."referralVolume" >= 50000 THEN 0.5 | ||
ELSE 0.4 | ||
END AS "referralRate", | ||
CASE | ||
WHEN d."depositDate" < '2022-07-22 17:00:00' THEN 3 | ||
ELSE 2 | ||
END AS multiplier | ||
FROM deposit d | ||
JOIN "deposit_referral_stat" d1 ON d."id" = d1."depositId" | ||
JOIN token t ON d."tokenId" = t.id | ||
JOIN historic_market_price hmp ON d."priceId" = hmp.id | ||
LEFT JOIN claim c on d."rewardsWindowIndex" = c."windowIndex" and (d."stickyReferralAddress" = c."account" or c.account = d."depositorAddr") | ||
ORDER BY d."depositDate" desc; | ||
`); | ||
|
||
await queryRunner.query( | ||
`CREATE UNIQUE INDEX "UK_deposits_mv_depositId_sourceChainId" ON deposits_mv ("depositId", "sourceChainId");`, | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP MATERIALIZED VIEW "deposits_mv"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.