Skip to content

Commit

Permalink
GIV airdrop detection (#4240)
Browse files Browse the repository at this point in the history
* Add initial code for GIV drop detection

* Add API url and processing for amounts

* Add test

* Add alternative XDAI node

* Fix test
  • Loading branch information
FrederikBolding committed Jan 5, 2022
1 parent 1203aef commit f97c4ad
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/assets/images/giveth-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions src/components/ActionsPanel/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ETHUUID,
EXT_URLS,
FAUCET_NETWORKS,
GIV_AIRDROP_LINK,
GOLEMV1UUID,
LENDUUID,
REPV1UUID,
Expand Down Expand Up @@ -176,6 +177,29 @@ export const actionTemplates: ActionTemplate[] = [
},
category: ACTION_CATEGORIES.THIRD_PARTY
},
{
name: ACTION_NAME.CLAIM_GIV,
heading: translateRaw('CLAIM_TOKENS_ACTION_HEADING', { $token: 'GIV' }),
icon: 'givLogo',
subHeading: ClaimSubHead,
body: [translate('CLAIM_TOKENS_ACTION_BODY', { $token: 'GIV' })],
filter: ({ claims }: ActionFilters) =>
claims[ClaimType.GIV]?.some((c) => c.state === ClaimState.UNCLAIMED),
priority: 30,
Component: ClaimTable,
props: {
type: ClaimType.GIV
},
button: {
component: ActionButton,
props: {
content: translateRaw('CLAIM_TOKENS_ACTION_BUTTON'),
to: GIV_AIRDROP_LINK,
external: true
}
},
category: ACTION_CATEGORIES.THIRD_PARTY
},
{
name: ACTION_NAME.MIGRATE_LEND,
heading: translateRaw('MIGRATE_LEND_ACTION_HEADING'),
Expand Down
2 changes: 2 additions & 0 deletions src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import nansenLogo from '@assets/images/credits/credits-nansen.svg';
import openSeaLogo from '@assets/images/credits/credits-opensea.svg';
import zapperLogo from '@assets/images/defizap/zapperLogo.svg';
import ensLogo from '@assets/images/ens/ens-icon.svg';
import givLogo from '@assets/images/giveth-logo.svg';
import golemLogo from '@assets/images/gol-logo.png';
import addressBookIcon from '@assets/images/icn-address-book.svg';
import buyIcon from '@assets/images/icn-buy.svg';
Expand Down Expand Up @@ -199,6 +200,7 @@ const svgIcons = {
zapperLogo,
'rep-logo': repLogo,
zeroxLogo,
givLogo,

/* Social Icons */
coinmarketcap,
Expand Down
2 changes: 2 additions & 0 deletions src/config/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export const DAPPNODE_CLAIM_API = 'https://dappnode.mycryptoapi.com/claims';
export const DAPPNODE_TOKEN_DISTRIBUTOR = '0x87d6180b65ad76a9443064dcd1596388fcc3ee2a';
export const ENS_CLAIM_API = 'https://ensclaims.mycryptoapi.com/v1/claims';
export const ENS_TOKEN_DISTRIBUTOR = '0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72';
export const GIV_CLAIM_API = 'https://giveth.mycryptoapi.com/v1/claims';
export const GIV_TOKEN_DISTRIBUTOR = '0xFad63adEFb8203F7605F25f6a921c8bf45604A5e';

export const LETS_ENCRYPT_URL = 'https://letsencrypt.org/';

Expand Down
1 change: 1 addition & 0 deletions src/config/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export const partnerLinks: Link[] = [
export const UNISWAP_LINK = 'https://app.uniswap.org/';
export const DAPPNODE_AIRDROP_LINK = 'https://app.dappnode.io/nodedrop';
export const ENS_AIRDROP_LINK = 'https://claim.ens.domains/';
export const GIV_AIRDROP_LINK = 'https://giv.giveth.io/claim';

export const MYC_WINTER_LINK = 'https://winter.mycrypto.com';

Expand Down
6 changes: 6 additions & 0 deletions src/database/data/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ export const NODES_CONFIG: { [key in NetworkId]: StaticNodeConfig[] } = {
type: NodeType.RPC,
service: 'xdaichain.com',
url: 'https://rpc.xdaichain.com/'
},
{
name: NetworkUtils.makeNodeName('xDAI', 'poanetwork.dev'),
type: NodeType.RPC,
service: 'poanetwork.dev',
url: 'https://xdai.poanetwork.dev/'
}
],
SmartChain: [
Expand Down
2 changes: 1 addition & 1 deletion src/database/generateDefaultValues.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Schema', () => {

it('adds Nodes to each Network', () => {
const nodes = toArray(defaultData[LSKeys.NETWORKS]).flatMap((n) => n.nodes);
expect(nodes).toHaveLength(54);
expect(nodes).toHaveLength(55);
});
});

Expand Down
12 changes: 12 additions & 0 deletions src/services/ApiService/Claims/Claims.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import mockAxios from 'jest-mock-axios';
import { UNISWAP_UNI_CLAIM_API } from '@config';
import { fAccount, fNetwork } from '@fixtures';
import { ClaimState, ClaimType, ITxValue } from '@types';
import { bigify, hexlify } from '@utils';

import { ClaimsService } from '.';

Expand Down Expand Up @@ -61,4 +62,15 @@ describe('ClaimsService', () => {
}
]);
});

it('can process amounts if needed', async () => {
const claims = await ClaimsService.instance.isClaimed(fNetwork, ClaimType.GIV, mockClaim);
expect(claims).toStrictEqual([
{
address: fAccount.address,
state: ClaimState.CLAIMED,
amount: hexlify(bigify(mockClaim[fAccount.address].Amount).div(10))
}
]);
});
});
4 changes: 3 additions & 1 deletion src/services/ApiService/Claims/Claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ export default class ClaimsService {
})
.then((data) => UniDistributor.isClaimed.decodeOutput(data))
.then(({ claimed }) => claimed);
const config = CLAIM_CONFIG[type];
const amount = config.processAmount ? config.processAmount(claim.Amount) : claim.Amount;
return {
address,
state: claimed ? ClaimState.CLAIMED : ClaimState.UNCLAIMED,
amount: claim.Amount
amount
};
}
return { address, state: ClaimState.NO_CLAIM, amount: '0x00' };
Expand Down
32 changes: 27 additions & 5 deletions src/services/ApiService/Claims/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,44 @@ import {
DAPPNODE_TOKEN_DISTRIBUTOR,
ENS_CLAIM_API,
ENS_TOKEN_DISTRIBUTOR,
GIV_CLAIM_API,
GIV_TOKEN_DISTRIBUTOR,
UNISWAP_TOKEN_DISTRIBUTOR,
UNISWAP_UNI_CLAIM_API
} from '@config';
import { ClaimType } from '@types';
import { ClaimType, NetworkId } from '@types';
import { bigify, hexlify } from '@utils';

export const CLAIM_CONFIG = {
interface ClaimConfig {
// Base URL
api: string;
// Contract Address
tokenDistributor: string;
network: NetworkId;
// In case the amounts need extra processing
processAmount?(hex: string): string;
}

export const CLAIM_CONFIG: Record<ClaimType, ClaimConfig> = {
[ClaimType.UNI]: {
api: UNISWAP_UNI_CLAIM_API,
tokenDistributor: UNISWAP_TOKEN_DISTRIBUTOR
tokenDistributor: UNISWAP_TOKEN_DISTRIBUTOR,
network: 'Ethereum'
},
[ClaimType.NODE]: {
api: DAPPNODE_CLAIM_API,
tokenDistributor: DAPPNODE_TOKEN_DISTRIBUTOR
tokenDistributor: DAPPNODE_TOKEN_DISTRIBUTOR,
network: 'Ethereum'
},
[ClaimType.ENS]: {
api: ENS_CLAIM_API,
tokenDistributor: ENS_TOKEN_DISTRIBUTOR
tokenDistributor: ENS_TOKEN_DISTRIBUTOR,
network: 'Ethereum'
},
[ClaimType.GIV]: {
api: GIV_CLAIM_API,
tokenDistributor: GIV_TOKEN_DISTRIBUTOR,
network: 'xDAI',
processAmount: (hex) => hexlify(bigify(hex).div(10))
}
};
17 changes: 11 additions & 6 deletions src/services/Store/store/claims.slice.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { createAction, createSelector, createSlice, PayloadAction } from '@reduxjs/toolkit';
import { all, call, put, select, takeLatest } from 'redux-saga/effects';

import { DEFAULT_NETWORK } from '@config';
import { ClaimsService } from '@services/ApiService';
import { CLAIM_CONFIG } from '@services/ApiService/Claims/config';
import { ClaimResult, ClaimType, Network, StoreAccount } from '@types';

import {
Expand All @@ -11,7 +13,7 @@ import {
getAccounts,
resetAndCreateManyAccounts
} from './account.slice';
import { selectDefaultNetwork } from './network.slice';
import { selectNetwork } from './network.slice';
import { AppState } from './root.reducer';

export const initialState = {
Expand Down Expand Up @@ -65,15 +67,18 @@ export function* claimsSaga() {
export function* fetchClaimsWorker() {
const accounts: StoreAccount[] = yield select(getAccounts);

const filteredAccounts = accounts.filter((a) => a.networkId === 'Ethereum');
const types = Object.values(ClaimType);

if (filteredAccounts.length === 0) return;
for (const type of types) {
const config = CLAIM_CONFIG[type];
const filteredAccounts = accounts.filter(
(a) => a.networkId === config.network || a.networkId === DEFAULT_NETWORK
);

const network: Network = yield select(selectDefaultNetwork);
if (filteredAccounts.length === 0) continue;

const types = Object.values(ClaimType);
const network: Network = yield select(selectNetwork(config.network));

for (const type of types) {
try {
const rawClaims = yield call(
[ClaimsService.instance, ClaimsService.instance.getClaims],
Expand Down
3 changes: 2 additions & 1 deletion src/types/claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { ITxValue } from './transactionFlow';
export enum ClaimType {
UNI = 'UNI',
NODE = 'NODE',
ENS = 'ENS'
ENS = 'ENS',
GIV = 'GIV'
}

export enum ClaimState {
Expand Down
1 change: 1 addition & 0 deletions src/types/userAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum ACTION_NAME {
CLAIM_UNI = 'claim_uni',
CLAIM_DAPPNODE = 'claim_dappnode',
CLAIM_ENS = 'claim_ens',
CLAIM_GIV = 'claim_giv',
RENEW_ENS = 'renew_ens',
BUY_HW = 'buy_hw',
MYC_MEMBERSHIP = 'myc_membership',
Expand Down

0 comments on commit f97c4ad

Please sign in to comment.