Skip to content

Commit

Permalink
feat: remove referral bonus (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
amateima committed Dec 13, 2022
1 parent bd1676f commit 9baf943
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
55 changes: 55 additions & 0 deletions migrations/1669984610621-DepositsMv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class DepositsMv1669984610621 implements MigrationInterface {
name = "DepositsMv1669984610621";

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",
d1."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",
d."acxUsdPrice",
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
WHEN d."depositDate" < '2022-12-13 00:00:00' THEN 2
ELSE 1
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 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"`);
}
}
5 changes: 3 additions & 2 deletions src/modules/deposit/model/DepositsMv.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ import { DepositReferralStats } from "../../referral/model/DepositReferralStats.
ELSE 0.4
END AS "referralRate",
CASE
WHEN d."depositDate" < '2022-07-22 17:00:00' THEN 3
ELSE 2
WHEN d."depositDate" < '2022-07-22 17:00:00' THEN 3
WHEN d."depositDate" < '2022-12-13 00:00:00' THEN 2
ELSE 1
END AS multiplier
FROM deposit d
JOIN "deposit_referral_stat" d1 ON d."id" = d1."depositId"
Expand Down

0 comments on commit 9baf943

Please sign in to comment.