Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Solana Donations Integration #1204

Merged
merged 16 commits into from
Dec 24, 2023
Merged

Conversation

CarlosQ96
Copy link
Collaborator

@CarlosQ96 CarlosQ96 commented Dec 19, 2023

Keeping the integration as simple as posible and backward compatible.

Need to update solana token I investigated and found different ids from Alquemy and Covalent websites, but I am not convinced with those values.

@CarlosQ96 CarlosQ96 force-pushed the feature_solana_create_donation branch from 6547240 to 618a40a Compare December 19, 2023 03:50
@CarlosQ96 CarlosQ96 changed the title modify create donation resolver to handle solana token Create Solana Donations Integration Dec 19, 2023
@CarlosQ96 CarlosQ96 force-pushed the feature_solana_create_donation branch from 70cd2fc to 7c925b0 Compare December 19, 2023 17:52
@CarlosQ96 CarlosQ96 marked this pull request as ready for review December 19, 2023 17:57
@CarlosQ96 CarlosQ96 requested a review from aminlatifi December 19, 2023 17:57
@CarlosQ96 CarlosQ96 force-pushed the feature_solana_create_donation branch from 7c925b0 to cb37669 Compare December 19, 2023 18:05
Comment on lines 12 to 15
.filter(token => token.networkId === NETWORK_IDS.SOLANA)
.map(t => {
t.address = t.address?.toLowerCase();
return t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter must be based on the chainType rather than networkId. Plus, address capitalization is important in Solana and must be preserved.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though, at this stage we will only add solana native token, so maybe it's better to apply more strict filtering conditions.

public async down(queryRunner: QueryRunner): Promise<void> {
const tokens = await queryRunner.query(`
SELECT * FROM token
WHERE "networkId" = ${NETWORK_IDS.SOLANA}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as above in reverting... chainType and native solana token address must be the criteria

{
name: 'Solana native token',
symbol: 'SOL',
address: '0x0000000000000000000000000000000000000000',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solana native token doesn't have any address, it's also mentioned #1175

But we we can rely on system programId 11111111111111111111111111111111 which is involved in native solana token transfer as well.

migration/data/seedTokens.ts Outdated Show resolved Hide resolved
@@ -26,7 +26,7 @@ export class MonoswapPriceAdapter implements PriceAdapterInterface {
const tokenPrices = await getMonoSwapTokenPrices(
params.symbol,
baseTokens,
params.networkId,
params.networkId!,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary?

test/testUtils.ts Outdated Show resolved Hide resolved
@@ -140,6 +141,7 @@ export const createFiatDonationFromOnramper = async (
fiatTransaction.payload.outCurrency,
priceChainId,
fiatTransaction.payload.outAmount,
ChainType.EVM,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make ChainType.EVM the default value and revert changes in other similar places.

@@ -75,22 +78,42 @@ export const createDonationQueryValidator = Joi.object({
amount: Joi.number()?.greater(0).required(),
transactionId: Joi.when('safeTransactionId', {
is: null || undefined || '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of is property is wrong or does not satisfy the intention of the original writer. The value will always evaluated to ''.

Comment on lines 108 to 116
Joi.string()
.allow(null, '')
.pattern(solanaTxRegex, 'Solana Transaction ID')
.messages({
'string.pattern.base': i18n.__(
translationErrorMessagesKeys.INVALID_TRANSACTION_ID,
),
}),
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This alternative is not needed as we don't accept safe transaction on solana

for (const token of SEED_DATA.TOKENS.solana) {
const tokenData = {
...token,
networkId: 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the constant value defined in the src/provider.ts

CarlosQ96 and others added 7 commits December 21, 2023 00:58
Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>
Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>
Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>
Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>
@CarlosQ96 CarlosQ96 force-pushed the feature_solana_create_donation branch from 4264b41 to 66d195f Compare December 22, 2023 05:38
@@ -2,6 +2,8 @@ import { ethers } from 'ethers';
import { ChainType } from '../types/network';
import { PublicKey } from '@solana/web3.js';

export const SOLANA_SYSTEM_ADDRESS = '11111111111111111111111111111111';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's Solana system program

@@ -19,6 +19,7 @@ import {
updateUserTotalDonated,
updateUserTotalReceived,
} from '../userService';
import { ChainType } from '../../types/network';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing

@@ -61,21 +75,21 @@ export const updateDonationPricesAndValues = async (
} else if (token?.cryptoCompareId) {
const priceUsd = await new CryptoComparePriceAdapter().getTokenPrice({
symbol: token.cryptoCompareId,
networkId: priceChainId,
networkId: priceChainId!,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

});
donation.priceUsd = toFixNumber(priceUsd, 4);
donation.valueUsd = toFixNumber(donation.amount * priceUsd, 4);
} else if (token?.coingeckoId) {
const priceUsd = await new CoingeckoPriceAdapter().getTokenPrice({
symbol: token.coingeckoId,
networkId: priceChainId,
networkId: priceChainId!,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing

});
donation.priceUsd = toFixNumber(priceUsd, 4);
donation.valueUsd = toFixNumber(donation.amount * priceUsd, 4);
} else {
const priceUsd = await new MonoswapPriceAdapter().getTokenPrice({
symbol: currency,
networkId: priceChainId,
networkId: priceChainId!,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing

Comment on lines 14 to 17
.map(t => {
t.address = t.address;
return t;
}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map doesn't do anything, it must be removed if you didn't have any intention of modification

const tokens = await queryRunner.query(`
SELECT * FROM token
WHERE "chainType" = ${ChainType.SOLANA}
AND "address" = ${SOLANA_SYSTEM_ADDRESS}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to limit it to the solana system program, this restriction must be applied on saving solana seed token above as well.

await queryRunner.query(
`
DELETE from token
WHERE "networkId" = ${NETWORK_IDS.SOLANA}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, the restriction on the address must be observed here

@CarlosQ96 CarlosQ96 force-pushed the feature_solana_create_donation branch from 03efa87 to 6a89f44 Compare December 23, 2023 05:43
Copy link
Member

@aminlatifi aminlatifi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @CarlosQ96, thanks.

Copy link
Collaborator

@mohammadranjbarz mohammadranjbarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @CarlosQ96 it needed lots of changes, LGTM

@aminlatifi aminlatifi merged commit 139f65e into staging Dec 24, 2023
3 checks passed
@aminlatifi aminlatifi deleted the feature_solana_create_donation branch December 24, 2023 07:24
mohammadranjbarz added a commit that referenced this pull request Jan 1, 2024
* Comment one test case

* Added fill snapshot round number back

* Removed blockNumber from snapshot in tests

* Fixed migrations to be compatible with removing blockNumber from history

* add project status to getVerificationFormByProjectId query

* Add sent matching fund to total donations of project and total received of users

related to Giveth/giveth-dapps-v2#3386

* Fix test case for adding matching fund to toal donation amount of projects

* Implement qfRoundStats webservice

related to Giveth/giveth-dapps-v2#3250

* Change allProjects webservice to support qfRoundSlug

related to Giveth/giveth-dapps-v2#3250

* Fix test cases to create qfRound

* Fix test cases to create qfRound

* Fix test cases to create qfRound

* Fix test cases to create qfRound

* Fix updateProjectWithVerificationForm

* Revert updateUserTotalReceived() funciton

* Fix updateUserTotalReceived() test case

* Fix updateUserTotalReceived() test case

* Fix mordor testnet node url

* Read node rpc urls from process.env instead of config

* Add log

* Fix etc provider url in github actions config

* Fix AddSlugToQfRound migration

* Remove unused tests

* add safeTransaction to donation logic

* fix uniqueness index on donation table

* comment a network tests

* fix nullability of transactionId

* make nonce nullable for safe donations

* add nullability to nonce in createdonationResolver

* remove undefined clause from joi validations

* Fix insertDonationsFromQfRoundHistory when can not find corosponding address

* Call refreshProjectDonationSummaryView() immediately after insertDonationsFromQfRoundHistory)

* Save non-evm user wallet address capitalization

* Updated the authentication service related address in test.env

* updated auth server in test env

* add validations for multisig donations

* add abis decoder for multisig transactions and parsers

* fetch from and to addresses correctly for multisig validations

* fix native token transfer for multisig transactions

* fix transaction amount in tests for multisig

* fix fromAddress edgecase for multisig

* make params options for transactionData

* Project Solana Address Support (#1200)

* Initial add solana address support to project address

* Added chaintype to graphql validator and project verification form

* Added chainType to token
Refactored project filter query builder
Added tests

* Fixed issue in test graphql query
Added some tests

* Fixed issues with tests

* Revert unwanted changes happend after merge

* Fixed issues happend after merge

* Fixed an issue in setting chainType in projectUpdate

* Revert "Removed snapshot block number" (#1202)

* comment uniqueness migration constraint (#1203)

* graphql allow null for transactionId (#1205)

* Create Solana Donations Integration (#1204)

* modify create donation resolver to handle solana token

* fix backward compatible tests

* add tests to solana donation creation

* add tests for solana resolvers (wip)

* fix solana donation tests and logic

* handle multiple solana tokens (future)

* fix some qfround tests

* add solana native token migration

* Update test/testUtils.ts solana token address

Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>

* Update migration/data/seedTokens.ts Decimals in Token

Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>

* Update migration/data/seedTokens.ts

Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>

* Update src/resolvers/donationResolver.test.ts

Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>

* solana feedback

* fix seed tokens

* fix solana donation flow and apply code feedback

* remove unnecesary code and improve migration

---------

Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>

* disable ratelimiter from env (#1212)

Co-authored-by: Carlos <carlos.quintero096@gmail.com>

* Hotfix/solana project address (#1210)

* Changed address invalid message

* Removed unused queries

* Fixed solana address verification problem

* Update master-pipeline.yml

* Verify Solana transactions (#1209)

* Add test cases for verifying solana transactions

related to #1171

* Fix build problems

* Refactor verifying solana transfer transactions

* Add disable cors and rate limiting to staging (#1221)

* disable ratelimiter from env (#1208)

* Write migration file to add missed optimism donations to db (#1213)

* Write migration file to add missed optimism donations to db

related to https://github.com/Giveth/giveth-dapps-v2/issues/3520

* Add another missed donation, make addresses lowercase before put in DB

* Move updating views functions out of the loop

* add missing optimism donation

---------

Co-authored-by: Carlos <carlos.quintero096@gmail.com>

* Update master-pipeline.yml

* disable dapp cors with envs

* Renamed variable

---------

Co-authored-by: CarlosQ96 <92376054+CarlosQ96@users.noreply.github.com>
Co-authored-by: mohammadranjbarz <mranjbar.z2993@gmail.com>
Co-authored-by: Carlos <carlos.quintero096@gmail.com>
Co-authored-by: Moe Shehab <52987806+mhmdksh@users.noreply.github.com>

* Add test and regex for solana token addresses (#1224)

* add test and regex for solana token addresses

* Upated solana wallet address and programId regex

---------

Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>

* Hotfix solana transction id validator (#1225)

* Improved solana transction id match regex

* Update solana transaction id regex

---------

Co-authored-by: CarlosQ96 <92376054+CarlosQ96@users.noreply.github.com>
Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>
Co-authored-by: Carlos <carlos.quintero096@gmail.com>
Co-authored-by: Krati Jain <kratijain88@gmail.com>
Co-authored-by: Mateo Daza <mateodaza@gmail.com>
Co-authored-by: Moe Shehab <52987806+mhmdksh@users.noreply.github.com>
aminlatifi added a commit that referenced this pull request Jan 11, 2024
* Multi sig release, 2023-12-31 (#1227)

* Comment one test case

* Added fill snapshot round number back

* Removed blockNumber from snapshot in tests

* Fixed migrations to be compatible with removing blockNumber from history

* add project status to getVerificationFormByProjectId query

* Add sent matching fund to total donations of project and total received of users

related to Giveth/giveth-dapps-v2#3386

* Fix test case for adding matching fund to toal donation amount of projects

* Implement qfRoundStats webservice

related to Giveth/giveth-dapps-v2#3250

* Change allProjects webservice to support qfRoundSlug

related to Giveth/giveth-dapps-v2#3250

* Fix test cases to create qfRound

* Fix test cases to create qfRound

* Fix test cases to create qfRound

* Fix test cases to create qfRound

* Fix updateProjectWithVerificationForm

* Revert updateUserTotalReceived() funciton

* Fix updateUserTotalReceived() test case

* Fix updateUserTotalReceived() test case

* Fix mordor testnet node url

* Read node rpc urls from process.env instead of config

* Add log

* Fix etc provider url in github actions config

* Fix AddSlugToQfRound migration

* Remove unused tests

* add safeTransaction to donation logic

* fix uniqueness index on donation table

* comment a network tests

* fix nullability of transactionId

* make nonce nullable for safe donations

* add nullability to nonce in createdonationResolver

* remove undefined clause from joi validations

* Fix insertDonationsFromQfRoundHistory when can not find corosponding address

* Call refreshProjectDonationSummaryView() immediately after insertDonationsFromQfRoundHistory)

* Save non-evm user wallet address capitalization

* Updated the authentication service related address in test.env

* updated auth server in test env

* add validations for multisig donations

* add abis decoder for multisig transactions and parsers

* fetch from and to addresses correctly for multisig validations

* fix native token transfer for multisig transactions

* fix transaction amount in tests for multisig

* fix fromAddress edgecase for multisig

* make params options for transactionData

* Project Solana Address Support (#1200)

* Initial add solana address support to project address

* Added chaintype to graphql validator and project verification form

* Added chainType to token
Refactored project filter query builder
Added tests

* Fixed issue in test graphql query
Added some tests

* Fixed issues with tests

* Revert unwanted changes happend after merge

* Fixed issues happend after merge

* Fixed an issue in setting chainType in projectUpdate

* Revert "Removed snapshot block number" (#1202)

* comment uniqueness migration constraint (#1203)

* graphql allow null for transactionId (#1205)

* Create Solana Donations Integration (#1204)

* modify create donation resolver to handle solana token

* fix backward compatible tests

* add tests to solana donation creation

* add tests for solana resolvers (wip)

* fix solana donation tests and logic

* handle multiple solana tokens (future)

* fix some qfround tests

* add solana native token migration

* Update test/testUtils.ts solana token address

Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>

* Update migration/data/seedTokens.ts Decimals in Token

Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>

* Update migration/data/seedTokens.ts

Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>

* Update src/resolvers/donationResolver.test.ts

Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>

* solana feedback

* fix seed tokens

* fix solana donation flow and apply code feedback

* remove unnecesary code and improve migration

---------

Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>

* disable ratelimiter from env (#1212)

Co-authored-by: Carlos <carlos.quintero096@gmail.com>

* Hotfix/solana project address (#1210)

* Changed address invalid message

* Removed unused queries

* Fixed solana address verification problem

* Update master-pipeline.yml

* Verify Solana transactions (#1209)

* Add test cases for verifying solana transactions

related to #1171

* Fix build problems

* Refactor verifying solana transfer transactions

* Add disable cors and rate limiting to staging (#1221)

* disable ratelimiter from env (#1208)

* Write migration file to add missed optimism donations to db (#1213)

* Write migration file to add missed optimism donations to db

related to https://github.com/Giveth/giveth-dapps-v2/issues/3520

* Add another missed donation, make addresses lowercase before put in DB

* Move updating views functions out of the loop

* add missing optimism donation

---------

Co-authored-by: Carlos <carlos.quintero096@gmail.com>

* Update master-pipeline.yml

* disable dapp cors with envs

* Renamed variable

---------

Co-authored-by: CarlosQ96 <92376054+CarlosQ96@users.noreply.github.com>
Co-authored-by: mohammadranjbarz <mranjbar.z2993@gmail.com>
Co-authored-by: Carlos <carlos.quintero096@gmail.com>
Co-authored-by: Moe Shehab <52987806+mhmdksh@users.noreply.github.com>

* Add test and regex for solana token addresses (#1224)

* add test and regex for solana token addresses

* Upated solana wallet address and programId regex

---------

Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>

* Hotfix solana transction id validator (#1225)

* Improved solana transction id match regex

* Update solana transaction id regex

---------

Co-authored-by: CarlosQ96 <92376054+CarlosQ96@users.noreply.github.com>
Co-authored-by: Amin Latifi <a.latifi.al@gmail.com>
Co-authored-by: Carlos <carlos.quintero096@gmail.com>
Co-authored-by: Krati Jain <kratijain88@gmail.com>
Co-authored-by: Mateo Daza <mateodaza@gmail.com>
Co-authored-by: Moe Shehab <52987806+mhmdksh@users.noreply.github.com>

* add isactive and fix adminjs for categories (#1223) (#1234)

---------

Co-authored-by: mohammadranjbarz <mranjbar.z2993@gmail.com>
Co-authored-by: CarlosQ96 <92376054+CarlosQ96@users.noreply.github.com>
Co-authored-by: Carlos <carlos.quintero096@gmail.com>
Co-authored-by: Krati Jain <kratijain88@gmail.com>
Co-authored-by: Mateo Daza <mateodaza@gmail.com>
Co-authored-by: Moe Shehab <52987806+mhmdksh@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants