Skip to content

Commit

Permalink
impl verify punkga quest (#1192) (#1193)
Browse files Browse the repository at this point in the history
  • Loading branch information
duonghb53 authored Jul 12, 2024
1 parent 37bbae5 commit 934b5d8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/micro3-campaign/const/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export enum ACTION_TYPE {
HoldAura = 'hold-aura',
AddLiquidity = 'add-lp',
Swap = 'swap-halo',
Punkga = 'punka-cp',
}

export enum HALO_ACTION_TYPE {
Expand All @@ -66,3 +67,5 @@ export const MICRO3_QUEUES = {

export const NATIVE = 'NATIVE';
export const NULL_EVM_ADDRESS = '0x0000000000000000000000000000000000000000';
export const PUNKGA_API =
'https://hasura.punkga.me/api/rest/public/user-xp?wallet_address=';
31 changes: 24 additions & 7 deletions src/micro3-campaign/micro3-campaign.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
MICRO3_CAMPAIGN,
NATIVE,
NULL_EVM_ADDRESS,
PUNKGA_API,
} from './const/common';
import { Explorer } from '../shared/entities/explorer.entity';
import { Repository } from 'typeorm';
Expand Down Expand Up @@ -56,6 +57,10 @@ export class Micro3CampaignService {
result = await this.verifySwap(chain, query);
break;

case ACTION_TYPE.Punkga:
result = await this.verifyPunkga(query);
break;

default:
return {
error: {
Expand Down Expand Up @@ -86,6 +91,20 @@ export class Micro3CampaignService {
};
}
}
async verifyPunkga(query: CampaignParamDto) {
const endpoint =
(this.configService.get('punkga.api') || PUNKGA_API) + query.address;

const results = await this.fetchDataFromAPI(endpoint);

if (results && results['user_level'].length > 0) {
const lvl = results['user_level'][0].level;

return lvl >= query.amount;
} else {
return false;
}
}
async verifySwap(chain: string, query: CampaignParamDto) {
return await this.verifyActionHalo(chain, HALO_ACTION_TYPE.Swap, query);
}
Expand Down Expand Up @@ -248,7 +267,7 @@ export class Micro3CampaignService {
HALO_BASE_URL,
chain,
)}/halo-pool/poolList`;
const pools = await this.fetchDataFromHalo(getPoolUrl, method);
const pools = await this.fetchDataFromAPI(getPoolUrl, method);

console.log(pools);
if (!pools) {
Expand All @@ -266,7 +285,7 @@ export class Micro3CampaignService {
chain,
)}/analytics/transactions?pageSize=10&type=${action}&poolId=${poolId}&sortBy=timeStamp&sortOrder=desc`;

const txs = await this.fetchDataFromHalo(getTxsUrl, method);
const txs = await this.fetchDataFromAPI(getTxsUrl, method);
if (txs) {
console.log(txs.data.res.results.map((tx) => tx.sender));
senderResult = senderResult.concat(
Expand All @@ -278,7 +297,7 @@ export class Micro3CampaignService {
return senderResult;
}

async fetchDataFromHalo(endpoint, method?) {
async fetchDataFromAPI(endpoint, method?) {
method = method ? method : 'GET';

try {
Expand All @@ -291,16 +310,14 @@ export class Micro3CampaignService {
if (response.data?.errors?.length > 0) {
this.logger.error(
response.data.errors,
`Error while querying from halo! ${JSON.stringify(
response.data.errors,
)}`,
`Error while querying ${JSON.stringify(response.data.errors)}`,
);
return null;
}

return response.data;
} catch (error) {
this.logger.error(endpoint, `Error while querying from halo! ${error}`);
this.logger.error(endpoint, `Error while querying ${error}`);
return null;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/shared/configs/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,7 @@ export default () => ({
haloTrade: {
graphQL: process.env.HALO_TRADE_GRAPHQL,
},
punkga: {
api: process.env.PUNKGA_API,
},
});

0 comments on commit 934b5d8

Please sign in to comment.