-
Notifications
You must be signed in to change notification settings - Fork 18
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
Conversation
6547240
to
618a40a
Compare
70cd2fc
to
7c925b0
Compare
7c925b0
to
cb37669
Compare
.filter(token => token.networkId === NETWORK_IDS.SOLANA) | ||
.map(t => { | ||
t.address = t.address?.toLowerCase(); | ||
return t; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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
migration/data/seedTokens.ts
Outdated
{ | ||
name: 'Solana native token', | ||
symbol: 'SOL', | ||
address: '0x0000000000000000000000000000000000000000', |
There was a problem hiding this comment.
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.
@@ -26,7 +26,7 @@ export class MonoswapPriceAdapter implements PriceAdapterInterface { | |||
const tokenPrices = await getMonoSwapTokenPrices( | |||
params.symbol, | |||
baseTokens, | |||
params.networkId, | |||
params.networkId!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary?
@@ -140,6 +141,7 @@ export const createFiatDonationFromOnramper = async ( | |||
fiatTransaction.payload.outCurrency, | |||
priceChainId, | |||
fiatTransaction.payload.outAmount, | |||
ChainType.EVM, |
There was a problem hiding this comment.
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 || '', |
There was a problem hiding this comment.
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 ''.
Joi.string() | ||
.allow(null, '') | ||
.pattern(solanaTxRegex, 'Solana Transaction ID') | ||
.messages({ | ||
'string.pattern.base': i18n.__( | ||
translationErrorMessagesKeys.INVALID_TRANSACTION_ID, | ||
), | ||
}), | ||
), |
There was a problem hiding this comment.
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
test/pre-test-scripts.ts
Outdated
for (const token of SEED_DATA.TOKENS.solana) { | ||
const tokenData = { | ||
...token, | ||
networkId: 0, |
There was a problem hiding this comment.
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
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>
4264b41
to
66d195f
Compare
src/utils/networks.ts
Outdated
@@ -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'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing
src/services/donationService.ts
Outdated
@@ -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!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
src/services/donationService.ts
Outdated
}); | ||
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!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing
src/services/donationService.ts
Outdated
}); | ||
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!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
likewise,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing
.map(t => { | ||
t.address = t.address; | ||
return t; | ||
}), |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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
03efa87
to
6a89f44
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM @CarlosQ96, thanks.
There was a problem hiding this 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
* 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>
* 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>
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.