Skip to content

Commit

Permalink
v1.21.0 (#1262)
Browse files Browse the repository at this point in the history
* Verify transfer spl-token on solana, supporting multi chain solana

related to #1175

* fix solana tests on devnet

* add solana additional tokens

* fix solana token transfer test

* improve joi schema chaintype validator

* Add another spl-token transfer test case, change validator of createDonation webservice

related to #1232 (comment)

* Refactor and change a nested if-else with witch case

* Removed only tags from tests

* Update src/utils/errorMessages.ts

Co-authored-by: Amin Latifi <[email protected]>

* Update src/utils/locales/en.json

Co-authored-by: Amin Latifi <[email protected]>

* Fill networkId for solana addresses when create/update projects

* Add some test tokens for solana dev chain

* Import lost donations into DB cronjob  (#1236)

* import donations from env vars and add tests

* Read LOST_DONATIONS_TX_HASHES from .env instead of config

* Fix build error

---------

Co-authored-by: Amin Latifi <[email protected]>
Co-authored-by: Mohammad Ranjbar Z <[email protected]>

* setup notification center disabling and reduce notifications

* Change filling networkId for solana

* Fix migration files for adding spl tokens on solana

* Modify create donation test cases for check filling networkId of solana donations

* comment out notification center methods interface

* Revert "comment out notification center methods interface"

This reverts commit 4a6dd8c.

* set logic as before, comment notification center methods not required

* move donation received logic to notification adapter

* Refactor get networkId for solana addresses and implement getAppropriateNetworkId

* Fix filling solana donations price (#1252)

* Fix filling solana donations price

related to Giveth/giveth-dapps-v2#3394 (comment)

* Add informative logs for filling value usd part

* Add log for createDonation webservice

* change type of transactionNetworkId to number in ajv schema

* Update createDonation to use correct networkId

* Added jobId to donation verification queue

* fix test env

* Import from Donation Backup Service (#1253)

* Added Donation Save Backup Adapter

* add backup service import cronjob

* add interface of used params from mongo data

* Change loading urls for backup service

* Refactor donationSaveBackupAdapter and adding mock adapter

* Removed unused package script

* Refactored createBackupDonation to reuse resolver

* Fix createBackupDonation() and write test case for that

* Add importError to failed donation mongo backup

---------

Co-authored-by: mohammadranjbarz <[email protected]>
Co-authored-by: Carlos <[email protected]>

* Fix query of getting failed donations from mongo API

* Add more logs for importing failed donations

* Change info logs to debug logs

* 1.21.0

* Add importDate to donation entity

* Fill importDate of donation correctly

---------

Co-authored-by: Mohammad Ranjbar Z <[email protected]>
Co-authored-by: Carlos <[email protected]>
Co-authored-by: CarlosQ96 <[email protected]>
  • Loading branch information
4 people authored Jan 23, 2024
1 parent 297bf38 commit 262be4d
Show file tree
Hide file tree
Showing 61 changed files with 1,622 additions and 372 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/develop-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ jobs:
CELO_ALFAJORES_SCAN_API_KEY: ${{ secrets.CELO_ALFAJORES_SCAN_API_KEY }}
MORDOR_ETC_TESTNET: ${{ secrets.MORDOR_ETC_TESTNET }}
ETC_NODE_HTTP_URL: ${{ secrets.ETC_NODE_HTTP_URL }}
SOLANA_NODE_RPC_URL: ${{ secrets.SOLANA_NODE_RPC_URL }}
SOLANA_TEST_NODE_RPC_URL: ${{ secrets.SOLANA_TEST_NODE_RPC_URL }}
SOLANA_DEVNET_NODE_RPC_URL: ${{ secrets.SOLANA_DEVNET_NODE_RPC_URL }}
SOLANA_MAINNET_NODE_RPC_URL: ${{ secrets.SOLANA_MAINNET_NODE_RPC_URL }}

publish:
needs: test
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/master-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ jobs:
CELO_ALFAJORES_SCAN_API_KEY: ${{ secrets.CELO_ALFAJORES_SCAN_API_KEY }}
MORDOR_ETC_TESTNET: ${{ secrets.MORDOR_ETC_TESTNET }}
ETC_NODE_HTTP_URL: ${{ secrets.ETC_NODE_HTTP_URL }}
SOLANA_NODE_RPC_URL: ${{ secrets.SOLANA_NODE_RPC_URL }}
SOLANA_TEST_NODE_RPC_URL: ${{ secrets.SOLANA_TEST_NODE_RPC_URL }}
SOLANA_DEVNET_NODE_RPC_URL: ${{ secrets.SOLANA_DEVNET_NODE_RPC_URL }}
SOLANA_MAINNET_NODE_RPC_URL: ${{ secrets.SOLANA_MAINNET_NODE_RPC_URL }}

publish:
needs: test
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/staging-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ jobs:
MORDOR_ETC_TESTNET: ${{ secrets.MORDOR_ETC_TESTNET }}
ETC_NODE_HTTP_URL: ${{ secrets.ETC_NODE_HTTP_URL }}
DROP_DATABASE: ${{ secrets.DROP_DATABASE }}
SOLANA_NODE_RPC_URL: ${{ secrets.SOLANA_NODE_RPC_URL }}
SOLANA_TEST_NODE_RPC_URL: ${{ secrets.SOLANA_TEST_NODE_RPC_URL }}
SOLANA_DEVNET_NODE_RPC_URL: ${{ secrets.SOLANA_DEVNET_NODE_RPC_URL }}
SOLANA_MAINNET_NODE_RPC_URL: ${{ secrets.SOLANA_MAINNET_NODE_RPC_URL }}

publish:
needs: test
Expand Down
15 changes: 15 additions & 0 deletions config/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ DISABLE_SERVER_RATE_LIMITER=false

DISABLE_SERVER_CORS=false


SOLANA_NODE_RPC_URL=
SOLANA_MAINNET_NODE_RPC_URL=
SOLANA_DEVNET_NODE_RPC_URL=
Expand All @@ -244,4 +245,18 @@ LOST_DONATIONS_TX_HASHES=
LOST_DONATIONS_QF_ROUND=
LOST_DONATIONS_NETWORK_ID=

SOLANA_CHAIN_ID=103
DISABLE_NOTIFICATION_CENTER=
ENABLE_IMPORT_DONATION_BACKUP=false
DONATION_SAVE_BACKUP_API_URL=
DONATION_SAVE_BACKUP_API_SECRET=
DONATION_SAVE_BACKUP_CRONJOB_EXPRESSION=
DONATION_SAVE_BACKUP_DATA_SOURCE=

# default value is failed_donation
DONATION_SAVE_BACKUP_COLLECTION=
# default value is failed_donation
DONATION_SAVE_BACKUP_DATABASE=

# Default value is saveBackup
DONATION_SAVE_BACKUP_ADAPTER=saveBackup
7 changes: 6 additions & 1 deletion config/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,21 @@ MATCHING_FUND_DONATIONS_FROM_ADDRESS=0x6e8873085530406995170Da467010565968C7C62
# Rate Limit config
DISABLE_SERVER_RATE_LIMITER=false
DISABLE_SERVER_CORS=false
SOLANA_NODE_RPC_URL=

SOLANA_NODE_RPC_URL=
SOLANA_MAINNET_NODE_RPC_URL=
SOLANA_DEVNET_NODE_RPC_URL=
SOLANA_TEST_NODE_RPC_URL=

SOLANA_CHAIN_ID=103
ENABLE_IMPORT_LOST_DONATIONS=false
IMPORT_LOST_DONATIONS_CRONJOB_EXPRESSION=
LOST_DONATIONS_TX_HASHES=0xb017677647418e1a35e59715f8e4e549d0e449d67faf5c73ed20e6d3ce67fb49
LOST_DONATIONS_QF_ROUND=
LOST_DONATIONS_NETWORK_ID=10

DISABLE_NOTIFICATION_CENTER=false
DONATION_SAVE_BACKUP_CRONJOB_EXPRESSION=
ENABLE_IMPORT_DONATION_BACKUP=false
DONATION_SAVE_BACKUP_API_URL=
DONATION_SAVE_BACKUP_API_SECRET=
32 changes: 20 additions & 12 deletions migration/1703044586989-addSolanaToken.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { NETWORK_IDS } from '../src/provider';
import { Token } from '../src/entities/token';
import seedTokens from './data/seedTokens';
import { ChainType } from '../src/types/network';
import { SOLANA_SYSTEM_PROGRAM } from '../src/utils/networks';
import { ENVIRONMENTS } from '../src/utils/utils';
import { MigrationInterface, QueryRunner } from 'typeorm';
import { NETWORK_IDS } from '../src/provider';
import { Token } from '../src/entities/token';

export class addSolanaToken1703044586989 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.manager.save(
Token,
seedTokens.filter(
async up(queryRunner: QueryRunner): Promise<void> {
let tokensData;
if (process.env.ENVIRONMENT === ENVIRONMENTS.PRODUCTION) {
tokensData = seedTokens.filter(
token =>
token.address === SOLANA_SYSTEM_PROGRAM &&
token.chainType === ChainType.SOLANA,
),
);
token.networkId === NETWORK_IDS.SOLANA_MAINNET &&
token.address === SOLANA_SYSTEM_PROGRAM,
);
} else {
tokensData = seedTokens.filter(
token =>
token.networkId === NETWORK_IDS.SOLANA_DEVNET &&
token.address === SOLANA_SYSTEM_PROGRAM,
);
}
await queryRunner.manager.save(Token, tokensData);
const tokens = await queryRunner.query(
`SELECT * FROM token WHERE "chainType" = $1 AND "address" = $2`,
[ChainType.SOLANA, SOLANA_SYSTEM_PROGRAM],
Expand All @@ -33,7 +41,7 @@ export class addSolanaToken1703044586989 implements MigrationInterface {
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
async down(queryRunner: QueryRunner): Promise<void> {
const tokens = await queryRunner.query(
`SELECT * FROM token WHERE "chainType" = $1 AND "address" = $2`,
[ChainType.SOLANA, SOLANA_SYSTEM_PROGRAM],
Expand Down
62 changes: 62 additions & 0 deletions migration/1704487070444-addSolanaSplTokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { Token } from '../src/entities/token';
import seedTokens from './data/seedTokens';
import { NETWORK_IDS } from '../src/provider';
import { ChainType } from '../src/types/network';
import { SOLANA_SYSTEM_PROGRAM } from '../src/utils/networks';
import { ENVIRONMENTS } from '../src/utils/utils';

export class addSolanaSplTokens1704487070444 implements MigrationInterface {
async up(queryRunner: QueryRunner): Promise<void> {
let tokensData;
if (process.env.ENVIRONMENT === ENVIRONMENTS.PRODUCTION) {
tokensData = seedTokens.filter(
token =>
token.networkId === NETWORK_IDS.SOLANA_MAINNET &&
token.address !== SOLANA_SYSTEM_PROGRAM,
);
} else {
tokensData = seedTokens.filter(
token =>
token.networkId === NETWORK_IDS.SOLANA_DEVNET &&
token.address !== SOLANA_SYSTEM_PROGRAM,
);
}
await queryRunner.manager.save(Token, tokensData);
const tokens = await queryRunner.query(
`SELECT * FROM token WHERE "chainType" = $1 AND "address" != $2`,
[ChainType.SOLANA, SOLANA_SYSTEM_PROGRAM],
);
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 ($1, $2), ($1, $3)`,
[token.id, givethOrganization.id, traceOrganization.id],
);
}
}

async down(queryRunner: QueryRunner): Promise<void> {
const tokens = await queryRunner.query(
`SELECT * FROM token WHERE "chainType" = $1 AND "address" != $2`,
[ChainType.SOLANA, SOLANA_SYSTEM_PROGRAM],
);
await queryRunner.query(
`DELETE FROM organization_tokens_token WHERE "tokenId" IN (${tokens
.map(token => token.id)
.join(',')})`,
);
await queryRunner.query(
`DELETE FROM token WHERE "chainType" = $1 AND "address" != $2`,
[ChainType.SOLANA, SOLANA_SYSTEM_PROGRAM],
);
}
}
15 changes: 15 additions & 0 deletions migration/1706012712969-add_import_date_to_donation_entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class addImportDateToDonationEntity1706012712969
implements MigrationInterface
{
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "donation" ADD COLUMN IF NOT EXISTS "importDate" TIMESTAMP WITH TIME ZONE`,
);
}

async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "donation" DROP COLUMN "importDate"`);
}
}
108 changes: 106 additions & 2 deletions migration/data/seedTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1262,13 +1262,117 @@ const seedTokens: ITokenData[] = [
decimals: 18,
networkId: NETWORK_IDS.MORDOR_ETC_TESTNET,
},
// TODO: Add solana token
// SOLANA mainnet
{
name: 'Solana native token',
symbol: 'SOL',
address: SOLANA_SYSTEM_PROGRAM,
decimals: 9,
networkId: NETWORK_IDS.SOLANA,
networkId: NETWORK_IDS.SOLANA_MAINNET,
chainType: ChainType.SOLANA,
coingeckoId: COINGECKO_TOKEN_IDS.SOLANA,
},
{
name: 'Marinade staked SOL',
symbol: 'mSOL',
address: 'mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So',
decimals: 9,
networkId: NETWORK_IDS.SOLANA_MAINNET,
chainType: ChainType.SOLANA,
coingeckoId: COINGECKO_TOKEN_IDS.MSOL,
},
{
name: 'USDC',
symbol: 'USDC',
address: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
decimals: 6,
networkId: NETWORK_IDS.SOLANA_MAINNET,
chainType: ChainType.SOLANA,
coingeckoId: COINGECKO_TOKEN_IDS.USDC,
},
{
name: 'Tether',
symbol: 'USDCT',
address: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
decimals: 6,
networkId: NETWORK_IDS.SOLANA_MAINNET,
chainType: ChainType.SOLANA,
coingeckoId: COINGECKO_TOKEN_IDS.USDT,
},
{
name: 'Raydium',
symbol: 'RAY',
address: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
decimals: 6,
networkId: NETWORK_IDS.SOLANA_MAINNET,
chainType: ChainType.SOLANA,
coingeckoId: COINGECKO_TOKEN_IDS.RAY,
},
{
name: 'BlazeStake Staked SOL',
symbol: 'BSOL',
address: 'bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1',
decimals: 9,
networkId: NETWORK_IDS.SOLANA_MAINNET,
chainType: ChainType.SOLANA,
coingeckoId: COINGECKO_TOKEN_IDS.BSOL,
},
{
name: 'Audius (Wormhole)',
symbol: 'AUDIO',
address: '9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM',
decimals: 8,
networkId: NETWORK_IDS.SOLANA_MAINNET,
chainType: ChainType.SOLANA,
coingeckoId: COINGECKO_TOKEN_IDS.AUDIO,
},
{
name: 'Mango',
symbol: 'MANGO',
address: 'MangoCzJ36AjZyKwVj3VnYU4GTonjfVEnJmvvWaxLac',
decimals: 6,
networkId: NETWORK_IDS.SOLANA_MAINNET,
chainType: ChainType.SOLANA,
coingeckoId: COINGECKO_TOKEN_IDS.MANGO,
},
{
name: 'Coin98',
symbol: 'C98',
address: 'C98A4nkJXhpVZNAZdHUA95RpTF3T4whtQubL3YobiUX9',
decimals: 6,
networkId: NETWORK_IDS.SOLANA_MAINNET,
chainType: ChainType.SOLANA,
coingeckoId: COINGECKO_TOKEN_IDS.C98,
},

// SOLANA devnet
{
name: 'Solana native token',
symbol: 'SOL',
address: SOLANA_SYSTEM_PROGRAM,
decimals: 9,
networkId: NETWORK_IDS.SOLANA_DEVNET,
chainType: ChainType.SOLANA,
coingeckoId: COINGECKO_TOKEN_IDS.SOLANA,
},

{
// Mohammad has deployed it on solana devnet, so you can get some tokens from him
name: 'Test SPL token',
symbol: 'TEST-SPL-TOKEN',
address: 'BrEahxkTrCKfjVy36pLD2gvVoMCUMEb1PinrAFtvJqPX',
decimals: 9,
networkId: NETWORK_IDS.SOLANA_DEVNET,
chainType: ChainType.SOLANA,
},

// SOLANA testnet
{
name: 'Solana native token',
symbol: 'SOL',
address: SOLANA_SYSTEM_PROGRAM,
decimals: 9,
networkId: NETWORK_IDS.SOLANA_TESTNET,
chainType: ChainType.SOLANA,
coingeckoId: COINGECKO_TOKEN_IDS.SOLANA,
},
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "giveth-graphql-api",
"version": "1.20.0",
"version": "1.21.0",
"description": "Backend GraphQL server for Giveth originally forked from Topia",
"main": "./dist/index.js",
"dependencies": {
Expand Down Expand Up @@ -114,6 +114,7 @@
"tslint:fix": "tslint -c tslint.json --fix '{src,test,migration}/**/*.ts'",
"test": "NODE_ENV=test mocha --config ./.mocharc.all-test.json",
"test:syncProjectsRequiredForListing": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/services/cronJobs/syncProjectsRequiredForListing.test.ts",
"test:backupDonationImport": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/services/cronJobs/backupDonationImport.test.ts",
"test:projectEntity": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/entities/project.test.ts",
"test:projectValidators": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/utils/validators/projectValidator.test.ts",
"test:onramperWebhook": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/services/onramper/webhookHandler.test.ts",
Expand Down
16 changes: 16 additions & 0 deletions src/adapters/adaptersFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { GitcoinAdapter } from './gitcoin/gitcoinAdapter';
import { GitcoinMockAdapter } from './gitcoin/gitcoinMockAdapter';
import { GivPowerBalanceAggregatorAdapter } from './givPowerBalanceAggregator/givPowerBalanceAggregatorAdapter';
import { GivPowerBalanceAggregatorAdapterMock } from './givPowerBalanceAggregator/givPowerBalanceAggregatorAdapterMock';
import { DonationSaveBackupAdapter } from './donationSaveBackup/donationSaveBackupAdapter';
import { DonationSaveBackupMockAdapter } from './donationSaveBackup/DonationSaveBackupMockAdapter';

const discordAdapter = new DiscordAdapter();
const googleAdapter = new GoogleAdapter();
Expand Down Expand Up @@ -118,3 +120,17 @@ export const getPowerBalanceAggregatorAdapter = () => {
return mockPowerBalanceAggregator;
}
};

const donationSaveBackupAdapter = new DonationSaveBackupAdapter();
const mockDonationSaveBackupAdapter = new DonationSaveBackupMockAdapter();

export const getDonationSaveBackupAdapter = () => {
switch (process.env.DONATION_SAVE_BACKUP_ADAPTER) {
case 'saveBackup':
return donationSaveBackupAdapter;
case 'mock':
return mockDonationSaveBackupAdapter;
default:
return mockDonationSaveBackupAdapter;
}
};
Loading

0 comments on commit 262be4d

Please sign in to comment.