Skip to content

Commit 407a4af

Browse files
distribution earn min balance
1 parent fdf5fcb commit 407a4af

File tree

7 files changed

+85
-26
lines changed

7 files changed

+85
-26
lines changed

packages/snaplet/.snaplet/dataModel.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,20 @@
17211721
"isId": false,
17221722
"maxLength": null
17231723
},
1724+
{
1725+
"id": "public.distributions.earn_min_balance",
1726+
"name": "earn_min_balance",
1727+
"columnName": "earn_min_balance",
1728+
"type": "int8",
1729+
"isRequired": true,
1730+
"kind": "scalar",
1731+
"isList": false,
1732+
"isGenerated": false,
1733+
"sequence": false,
1734+
"hasDefaultValue": true,
1735+
"isId": false,
1736+
"maxLength": null
1737+
},
17241738
{
17251739
"name": "distribution_shares",
17261740
"type": "distribution_shares",

packages/snaplet/.snaplet/snaplet-client.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ type Override = {
123123
token_addr?: string;
124124
token_decimals?: string;
125125
tranche_id?: string;
126+
earn_min_balance?: string;
126127
distribution_shares?: string;
127128
distribution_verification_values?: string;
128129
distribution_verifications?: string;
@@ -853,6 +854,7 @@ export interface Fingerprint {
853854
chainId?: FingerprintNumberField;
854855
tokenDecimals?: FingerprintNumberField;
855856
trancheId?: FingerprintNumberField;
857+
earnMinBalance?: FingerprintNumberField;
856858
distributionShares?: FingerprintRelationField;
857859
distributionVerificationValues?: FingerprintRelationField;
858860
distributionVerifications?: FingerprintRelationField;

packages/snaplet/.snaplet/snaplet.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ interface Table_public_distributions {
129129
token_addr: string | null;
130130
token_decimals: number | null;
131131
tranche_id: number;
132+
earn_min_balance: number;
132133
}
133134
interface Table_realtime_extensions {
134135
id: string;

supabase/database-generated.types.ts

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,7 @@ export type Database = {
6161
updated_at?: string
6262
user_id?: string | null
6363
}
64-
Relationships: [
65-
{
66-
foreignKeyName: "affiliate_stats_user_id_fkey"
67-
columns: ["user_id"]
68-
isOneToOne: true
69-
referencedRelation: "profiles"
70-
referencedColumns: ["id"]
71-
},
72-
]
64+
Relationships: []
7365
}
7466
chain_addresses: {
7567
Row: {
@@ -257,6 +249,7 @@ export type Database = {
257249
claim_end: string
258250
created_at: string
259251
description: string | null
252+
earn_min_balance: number
260253
fixed_pool_bips: number
261254
hodler_min_balance: number
262255
hodler_pool_bips: number
@@ -279,6 +272,7 @@ export type Database = {
279272
claim_end: string
280273
created_at?: string
281274
description?: string | null
275+
earn_min_balance?: number
282276
fixed_pool_bips: number
283277
hodler_min_balance: number
284278
hodler_pool_bips: number
@@ -301,6 +295,7 @@ export type Database = {
301295
claim_end?: string
302296
created_at?: string
303297
description?: string | null
298+
earn_min_balance?: number
304299
fixed_pool_bips?: number
305300
hodler_min_balance?: number
306301
hodler_pool_bips?: number
@@ -422,22 +417,7 @@ export type Database = {
422417
referred_id?: string
423418
referrer_id?: string
424419
}
425-
Relationships: [
426-
{
427-
foreignKeyName: "referrals_referred_id_fkey"
428-
columns: ["referred_id"]
429-
isOneToOne: true
430-
referencedRelation: "profiles"
431-
referencedColumns: ["id"]
432-
},
433-
{
434-
foreignKeyName: "referrals_referrer_id_fkey"
435-
columns: ["referrer_id"]
436-
isOneToOne: false
437-
referencedRelation: "profiles"
438-
referencedColumns: ["id"]
439-
},
440-
]
420+
Relationships: []
441421
}
442422
send_account_created: {
443423
Row: {
@@ -1639,6 +1619,14 @@ export type Database = {
16391619
}
16401620
Relationships: []
16411621
}
1622+
send_earn_balances_timeline: {
1623+
Row: {
1624+
balance: number | null
1625+
block_time: number | null
1626+
owner: string | null
1627+
}
1628+
Relationships: []
1629+
}
16421630
}
16431631
Functions: {
16441632
calculate_and_insert_send_ceiling_verification: {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
create extension if not exists "pgjwt" with schema "extensions";
2+
3+
4+
alter table "public"."distributions" add column "earn_min_balance" bigint not null default 0;
5+
6+
update distributions set earn_min_balance = 5e6 where number = 16;
7+
8+
CREATE INDEX idx_earn_deposit_owner_blocktime ON public.send_earn_deposit USING btree (owner, block_time DESC);
9+
10+
CREATE INDEX idx_earn_withdraw_owner_blocktime ON public.send_earn_withdraw USING btree (owner, block_time DESC);
11+
12+
create or replace view "public"."send_earn_balances_timeline" as WITH all_transactions AS (
13+
SELECT send_earn_deposit.owner,
14+
send_earn_deposit.block_time,
15+
send_earn_deposit.assets AS balance
16+
FROM send_earn_deposit
17+
UNION ALL
18+
SELECT send_earn_withdraw.owner,
19+
send_earn_withdraw.block_time,
20+
(- send_earn_withdraw.assets) AS balance
21+
FROM send_earn_withdraw
22+
)
23+
SELECT all_transactions.owner,
24+
all_transactions.block_time,
25+
sum(all_transactions.balance) OVER (PARTITION BY all_transactions.owner ORDER BY all_transactions.block_time ROWS UNBOUNDED PRECEDING) AS balance
26+
FROM all_transactions
27+
ORDER BY all_transactions.block_time;
28+
29+
30+

supabase/schemas/distributions.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ CREATE TABLE IF NOT EXISTS "public"."distributions" (
6464
"merkle_drop_addr" "bytea",
6565
"token_addr" "bytea",
6666
"token_decimals" numeric,
67-
"tranche_id" integer NOT NULL
67+
"tranche_id" integer NOT NULL,
68+
"earn_min_balance" bigint NOT NULL DEFAULT 0
6869
);
6970

7071
ALTER TABLE "public"."distributions" OWNER TO "postgres";

supabase/schemas/send_earn.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,35 @@ CREATE OR REPLACE VIEW "public"."send_earn_balances" WITH ("security_invoker"='o
548548

549549
ALTER TABLE "public"."send_earn_balances" OWNER TO "postgres";
550550

551+
CREATE OR REPLACE VIEW send_earn_balances_timeline AS
552+
WITH all_transactions AS (
553+
SELECT owner, block_time, assets as balance
554+
FROM send_earn_deposit
555+
UNION ALL
556+
SELECT owner, block_time, -assets as balance
557+
FROM send_earn_withdraw
558+
)
559+
SELECT
560+
owner,
561+
block_time,
562+
SUM(balance) OVER (
563+
PARTITION BY owner
564+
ORDER BY block_time
565+
ROWS UNBOUNDED PRECEDING
566+
) as balance
567+
FROM all_transactions
568+
ORDER BY block_time;
569+
570+
ALTER TABLE "public"."send_earn_balances_timeline" OWNER TO "postgres";
571+
551572
-- Indexes
552573
CREATE INDEX "send_earn_create_block_num" ON "public"."send_earn_create" USING "btree" ("block_num");
553574
CREATE INDEX "send_earn_create_block_time" ON "public"."send_earn_create" USING "btree" ("block_time");
554575
CREATE INDEX "send_earn_create_send_earn" ON "public"."send_earn_create" USING "btree" ("send_earn");
555576
CREATE INDEX "send_earn_deposit_block_num" ON "public"."send_earn_deposit" USING "btree" ("block_num");
556577
CREATE INDEX "send_earn_deposit_block_time" ON "public"."send_earn_deposit" USING "btree" ("block_time");
578+
CREATE INDEX idx_earn_deposit_owner_blocktime ON "public"."send_earn_deposit" USING "btree" ("owner", "block_time" DESC);
579+
CREATE INDEX idx_earn_withdraw_owner_blocktime ON "public"."send_earn_withdraw" USING "btree" ("owner", "block_time" DESC);
557580
CREATE INDEX "send_earn_deposit_owner_idx" ON "public"."send_earn_deposit" USING "btree" ("owner", "log_addr");
558581
CREATE INDEX "send_earn_new_affiliate_affiliate_idx" ON "public"."send_earn_new_affiliate" USING "btree" ("affiliate");
559582
CREATE INDEX "send_earn_new_affiliate_block_num" ON "public"."send_earn_new_affiliate" USING "btree" ("block_num");

0 commit comments

Comments
 (0)