Skip to content

Commit

Permalink
Merge pull request #1783 from Giveth/staging
Browse files Browse the repository at this point in the history
Next Release Aug 2024
  • Loading branch information
CarlosQ96 authored Aug 28, 2024
2 parents 3696284 + c0765f4 commit 1c3a62c
Show file tree
Hide file tree
Showing 52 changed files with 2,498 additions and 123 deletions.
6 changes: 5 additions & 1 deletion config/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ BCRYPT_SALT=$2b$10$44gNUOnBXavOBMPOqzd48e
XDAI_NODE_HTTP_URL=https://xxxxxx.xdai.quiknode.pro/
ETHERSCAN_MAINNET_API_URL=https://api.etherscan.io/api
ETHERSCAN_ROPSTEN_API_URL=https://api-ropsten.etherscan.io/api
ETHERSCAN_GOERLI_API_URL=https://api-goerli.etherscan.io/api
ETHERSCAN_SEPOLIA_API_URL=https://api-sepolia.etherscan.io/api
POLYGON_SCAN_API_URL=https://api.polygonscan.com/api
POLYGON_SCAN_API_KEY=0000000000000000000000000000000000
OPTIMISTIC_SCAN_API_URL=https://api-optimistic.etherscan.io/api
Expand Down Expand Up @@ -321,4 +321,8 @@ ZKEVM_MAINNET_NODE_HTTP_URL=
# ZKEVM CARDONA we should fill it as Infura doesnt support polygon zkevm
ZKEVM_CARDONA_NODE_HTTP_URL=

# STELLAR
STELLAR_HORIZON_API_URL=https://horizon.stellar.org
STELLAR_SCAN_API_URL=https://stellar.expert/explorer/public

ENDAOMENT_ADMIN_WALLET_ADDRESS=0xfE3524e04E4e564F9935D34bB5e80c5CaB07F5b4
6 changes: 5 additions & 1 deletion config/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ MAINNET_NODE_WS_URL=xxx
INFURA_ID=xxx
ETHERSCAN_MAINNET_API_URL=https://api.etherscan.io/api
ETHERSCAN_ROPSTEN_API_URL=https://api-ropsten.etherscan.io/api
ETHERSCAN_GOERLI_API_URL=https://api-goerli.etherscan.io/api
ETHERSCAN_SEPOLIA_API_URL=https://api-sepolia.etherscan.io/api
POLYGON_SCAN_API_URL=https://api.polygonscan.com/api
OPTIMISTIC_SCAN_API_URL=https://api-optimistic.etherscan.io/api
OPTIMISTIC_SEPOLIA_SCAN_API_URL=https://api-sepolia-optimistic.etherscan.io/api
Expand Down Expand Up @@ -252,4 +252,8 @@ ZKEVM_MAINNET_NODE_HTTP_URL=https://polygon-zkevm.drpc.org
# ZKEVM CARDONA we should fill it as Infura doesnt support polygon zkevm, I found this rpc link from https://chainlist.org/chain/2442
ZKEVM_CARDONA_NODE_HTTP_URL=https://rpc.cardona.zkevm-rpc.com

# STELLAR
STELLAR_HORIZON_API_URL=https://horizon.stellar.org
STELLAR_SCAN_API_URL=https://stellar.expert/explorer/public

ENDAOMENT_ADMIN_WALLET_ADDRESS=0xfE3524e04E4e564F9935D34bB5e80c5CaB07F5b4
17 changes: 17 additions & 0 deletions migration/1722379846122-AddMemoToProjectAddressFields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddMemoToProjectAddressFields1722379846122
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "project_address" ADD COLUMN IF NOT EXISTS "memo" VARCHAR`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "project_address" DROP COLUMN IF EXISTS "memo"`,
);
}
}
69 changes: 69 additions & 0 deletions migration/1722475689162-AddStellarTokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { Token } from '../src/entities/token';
import seedTokens from './data/seedTokens';
import { NETWORK_IDS } from '../src/provider';

export class AddStellarTokens1722475689162 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
const networkId = NETWORK_IDS.STELLAR_MAINNET;

//add isQR code to token
await queryRunner.query(
`ALTER TABLE token ADD COLUMN IF NOT EXISTS "isQR" BOOLEAN DEFAULT FALSE NOT NULL`,
);

await queryRunner.manager.save(
Token,
seedTokens
.filter(token => token.networkId === networkId)
.map(token => {
const t = {
...token,
};
t.address = t.address?.toUpperCase();
return t;
}),
);
const tokens = await queryRunner.query(`
SELECT * FROM token
WHERE "networkId" = ${networkId}
`);
const givethOrganization = (
await queryRunner.query(`SELECT * FROM organization
WHERE label='giveth'`)
)[0];

const traceOrganization = (
await queryRunner.query(`SELECT * FROM organization
WHERE label='trace'`)
)[0];

for (const token of tokens) {
// Add all Stellar tokens to Giveth organization
await queryRunner.query(`INSERT INTO organization_tokens_token ("tokenId","organizationId") VALUES
(${token.id}, ${givethOrganization.id}),
(${token.id}, ${traceOrganization.id})
;`);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
const networkId = NETWORK_IDS.STELLAR_MAINNET;

await queryRunner.query(`ALTER TABLE token DROP COLUMN IF EXISTS "isQR"`);

const tokens = await queryRunner.query(`
SELECT * FROM token
WHERE "networkId" = ${networkId}
`);

for (const token of tokens) {
await queryRunner.query(
`DELETE FROM organization_tokens_token WHERE "tokenId" = ${token.id}`,
);
}
await queryRunner.query(
`DELETE FROM token WHERE "networkId" = ${networkId}`,
);
}
}
39 changes: 39 additions & 0 deletions migration/1722800845343-AddDraftDonationQRFields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddDraftDonationQRFields1722800845343
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE draft_donation
ADD COLUMN IF NOT EXISTS "toWalletMemo" VARCHAR NULL,
ADD COLUMN IF NOT EXISTS "qrCodeDataUrl" TEXT NULL,
ADD COLUMN IF NOT EXISTS "isQRDonation" BOOLEAN DEFAULT FALSE;
`);

// update enum draft_donation_chaintype_enum (add 'STELLAR');
await queryRunner.query(
`ALTER TYPE public.draft_donation_chaintype_enum ADD VALUE IF NOT EXISTS 'STELLAR';`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE draft_donation
DROP COLUMN IF EXISTS "toWalletMemo",
DROP COLUMN IF EXISTS "qrCodeDataUrl",
DROP COLUMN IF EXISTS "isQRDonation";
`);

// update enum draft_donation_chaintype_enum (remove 'STELLAR');
await queryRunner.query(`
DELETE FROM pg_enum
WHERE enumlabel = 'STELLAR'
AND enumtypid = (
SELECT oid
FROM pg_type
WHERE typname = 'draft_donation_chaintype_enum'
);
`);
}
}
35 changes: 35 additions & 0 deletions migration/1722860378721-UpdateDraftDonationIndex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class UpdateDraftDonationIndex1722860378721
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "IDX_af180374473ea402e7595196a6"`);
await queryRunner.query(`
CREATE UNIQUE INDEX IF NOT EXISTS "IDX_af180374473ea402e7595196a6"
ON public.draft_donation USING btree
("fromWalletAddress" COLLATE pg_catalog."default" ASC NULLS LAST,
"toWalletAddress" COLLATE pg_catalog."default" ASC NULLS LAST,
"networkId" ASC NULLS LAST,
amount ASC NULLS LAST,
currency COLLATE pg_catalog."default" ASC NULLS LAST)
TABLESPACE pg_default
WHERE status = 'pending'::draft_donation_status_enum AND "isQRDonation" = false;
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "IDX_af180374473ea402e7595196a6"`);
await queryRunner.query(`
CREATE UNIQUE INDEX IF NOT EXISTS "IDX_af180374473ea402e7595196a6"
ON public.draft_donation USING btree
("fromWalletAddress" COLLATE pg_catalog."default" ASC NULLS LAST,
"toWalletAddress" COLLATE pg_catalog."default" ASC NULLS LAST,
"networkId" ASC NULLS LAST,
amount ASC NULLS LAST,
currency COLLATE pg_catalog."default" ASC NULLS LAST)
TABLESPACE pg_default
WHERE status = 'pending'::draft_donation_status_enum;
`);
}
}
30 changes: 30 additions & 0 deletions migration/1722963339892-UpdateDonationIndex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class UpdateDonationIndex1722963339892 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
// update donation table
await queryRunner.query(`
ALTER TABLE "donation"
ADD COLUMN IF NOT EXISTS "isQRDonation" boolean DEFAULT false,
ADD COLUMN IF NOT EXISTS "toWalletMemo" text;
`);

await queryRunner.query(`DROP INDEX "idx_donation_project_user"`);
await queryRunner.query(
`CREATE INDEX IF NOT EXISTS idx_donation_project_user ON donation("projectId", "userId", "valueUsd") WHERE "status" = 'verified' AND "recurringDonationId" IS NULL AND "isQRDonation" = false AND "userId" IS NOT NULL`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "idx_donation_project_user"`);
await queryRunner.query(
`CREATE INDEX IF NOT EXISTS idx_donation_project_user ON donation("projectId", "userId", "valueUsd") WHERE "status" = 'verified' AND "recurringDonationId" IS NULL`,
);

await queryRunner.query(`
ALTER TABLE "donation"
DROP COLUMN IF EXISTS "isQRDonation",
DROP COLUMN IF EXISTS "toWalletMemo";
`);
}
}
17 changes: 17 additions & 0 deletions migration/1723025859680-AddExpirationDateToDraftDonation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddExpirationDateToDraftDonation1723025859680
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE draft_donation ADD COLUMN IF NOT EXISTS "expiresAt" TIMESTAMP`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE draft_donation DROP COLUMN IF EXISTS "expiresAt"`,
);
}
}
65 changes: 65 additions & 0 deletions migration/1724166731604-addSepoliaToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { Token } from '../src/entities/token';
import { NETWORK_IDS } from '../src/provider';
import seedTokens from './data/seedTokens';
import config from '../src/config';

export class AddSepoliaToken1724166731604 implements MigrationInterface {
async up(queryRunner: QueryRunner): Promise<void> {
const environment = config.get('ENVIRONMENT') as string;
// We don't add sepolia tokens in production ENV
if (environment === 'production') return;

await queryRunner.manager.save(
Token,
seedTokens
.filter(token => token.networkId === NETWORK_IDS.SEPOLIA)
.map(token => {
const t = {
...token,
};
t.address = t.address?.toLowerCase();
delete t.chainType;
return t;
}),
);

const tokens = await queryRunner.query(`
SELECT * FROM token
WHERE "networkId" = ${NETWORK_IDS.SEPOLIA}
`);

const givethOrganization = (
await queryRunner.query(`SELECT * FROM organization
WHERE label='giveth'`)
)[0];

const traceOrganization = (
await queryRunner.query(`SELECT * FROM organization
WHERE label='trace'`)
)[0];

for (const token of tokens) {
await queryRunner.query(`INSERT INTO organization_tokens_token ("tokenId","organizationId") VALUES
(${token.id}, ${givethOrganization.id}),
(${token.id}, ${traceOrganization.id})
;`);
}
}

async down(queryRunner: QueryRunner): Promise<void> {
const environment = config.get('ENVIRONMENT') as string;
// We don't add sepolia tokens in production ENV
if (environment === 'production') return;
await queryRunner.query(`
DELETE FROM organization_tokens_token
WHERE "tokenId" IN (
SELECT id FROM token WHERE "networkId" = ${NETWORK_IDS.SEPOLIA}
);
`);

await queryRunner.query(`
DELETE FROM token WHERE "networkId" = ${NETWORK_IDS.SEPOLIA};
`);
}
}
35 changes: 35 additions & 0 deletions migration/1724168597216-ChangeProjectAddressToSepolia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class ChangeProjectAddressToSepolia1724168597216
implements MigrationInterface
{
async up(queryRunner: QueryRunner): Promise<void> {
const projectAddressTableExists =
await queryRunner.hasTable('project_address');
if (!projectAddressTableExists) {
// eslint-disable-next-line no-console
console.log('The project_address table doesn’t exist');
return;
}
await queryRunner.query(`
UPDATE project_address
SET "networkId" = 11155111
WHERE "networkId" = 5
`);
}

async down(queryRunner: QueryRunner): Promise<void> {
const projectAddressTableExists =
await queryRunner.hasTable('project_address');
if (!projectAddressTableExists) {
// eslint-disable-next-line no-console
console.log('The project_address table doesn’t exist');
return;
}
await queryRunner.query(`
UPDATE project_address
SET "networkId" = 5
WHERE "networkId" = 11155111
`);
}
}
Loading

0 comments on commit 1c3a62c

Please sign in to comment.