Skip to content

Commit

Permalink
Merge pull request #43 from GeneralMagicio/supportMATICToken
Browse files Browse the repository at this point in the history
Support matic token
  • Loading branch information
ae2079 authored Sep 4, 2024
2 parents ea1387e + d49de17 commit dd69925
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 26 deletions.
33 changes: 33 additions & 0 deletions migration/1725326426460-seedTokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { NETWORK_IDS } from '../src/provider';
import { Token } from '../src/entities/token';

const tokens = [
{
name: 'Matic Token',
symbol: 'MATIC',
decimals: 18,
address: '0xa2036f0538221a77a3937f1379699f44945018d0',
coingeckoId: 'matic-network',
networkId: NETWORK_IDS.ZKEVM_MAINNET,
},
];

export class SeedTokens1725326426460 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.manager.save(Token, tokens);
}

public async down(queryRunner: QueryRunner): Promise<void> {
for (const token of tokens) {
await queryRunner.query(
`
DELETE FROM "token"
WHERE "address" = $1
AND "networkId" = $2;
`,
[token.address, token.networkId],
);
}
}
}
54 changes: 33 additions & 21 deletions src/resolvers/projectResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ import {
addBulkProjectSocialMedia,
removeProjectSocialMedia,
} from '../repositories/projectSocialMediaRepository';
import {
QACC_DONATION_TOKEN_ADDRESS,
QACC_DONATION_TOKEN_SYMBOL,
} from '../utils/qacc';

const projectUpdatsCacheDuration = 1000 * 60 * 60;

Expand Down Expand Up @@ -1694,29 +1698,37 @@ export class ProjectResolver {

@Query(_returns => [Token])
async getProjectAcceptTokens(
@Arg('projectId') projectId: number,
@Arg('projectId', { nullable: true }) _projectId: number,
): Promise<Token[]> {
try {
const organization = await Organization.createQueryBuilder('organization')
.innerJoin(
'organization.projects',
'project',
'project.id = :projectId',
{ projectId },
)
.leftJoinAndSelect('organization.tokens', 'tokens')
.leftJoin(
'project_address',
'pa',
'pa.projectId = project.id AND pa.isRecipient = true',
)
.andWhere('pa.networkId = tokens.networkId')
.getOne();

if (!organization) {
return [];
}
return sortTokensByOrderAndAlphabets(organization.tokens);
// const organization = await Organization.createQueryBuilder('organization')
// .innerJoin(
// 'organization.projects',
// 'project',
// 'project.id = :projectId',
// { projectId },
// )
// .leftJoinAndSelect('organization.tokens', 'tokens')
// .leftJoin(
// 'project_address',
// 'pa',
// 'pa.projectId = project.id AND pa.isRecipient = true',
// )
// .andWhere('pa.networkId = tokens.networkId')
// .getOne();
//
// if (!organization) {
// return [];
// }
// return sortTokensByOrderAndAlphabets(organization.tokens);
const filteredTokens = await Token.find({
where: {
networkId: QACC_NETWORK_ID,
address: QACC_DONATION_TOKEN_ADDRESS,
symbol: QACC_DONATION_TOKEN_SYMBOL,
},
});
return sortTokensByOrderAndAlphabets(filteredTokens);
} catch (e) {
logger.error('getProjectAcceptTokens error', e);
throw e;
Expand Down
1 change: 1 addition & 0 deletions src/services/chains/evm/transactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ async function getTransactionDetailForTokenTransfer(
}
}

// we check the token address here and didn't get it form front-end
if (transaction && transactionTokenAddress !== token.address.toLowerCase()) {
throw new Error(
i18n.__(
Expand Down
6 changes: 3 additions & 3 deletions src/utils/qacc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { findActiveEarlyAccessRound } from '../repositories/earlyAccessRoundRepo

export const QACC_DONATION_TOKEN_ADDRESS: string =
(config.get('QACC_DONATION_TOKEN_ADDRESS') as string) ||
'0xa2036f0538221a77A3937F1379699f44945018d0'; //https://zkevm.polygonscan.com/token/0xa2036f0538221a77a3937f1379699f44945018d0#readContract
'0xa2036f0538221a77a3937f1379699f44945018d0'; //https://zkevm.polygonscan.com/token/0xa2036f0538221a77a3937f1379699f44945018d0#readContract
export const QACC_DONATION_TOKEN_SYMBOL =
(config.get('QACC_DONATION_TOKEN_SYMBOL') as string) || 'QAT';
(config.get('QACC_DONATION_TOKEN_SYMBOL') as string) || 'MATIC';
export const QACC_DONATION_TOKEN_NAME =
(config.get('QACC_DONATION_TOKEN_NAME') as string) || 'QAT Name';
(config.get('QACC_DONATION_TOKEN_NAME') as string) || 'Matic token';
export const QACC_DONATION_TOKEN_DECIMALS =
(+config.get('QACC_DONATION_TOKEN_DECIMALS') as number) || 18;
export const QACC_DONATION_TOKEN_COINGECKO_ID =
Expand Down
4 changes: 2 additions & 2 deletions test/graphqlQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ export const projectByIdQuery = `

export const getProjectsAcceptTokensQuery = `
query(
$projectId: Float!,
$projectId: Float,
){
getProjectAcceptTokens(
projectId:$projectId){
Expand All @@ -1519,7 +1519,7 @@ export const getProjectsAcceptTokensQuery = `
networkId
chainType
decimals
mainnetAddress
address
name
}
}
Expand Down

0 comments on commit dd69925

Please sign in to comment.