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

Support stellar donations #60

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/givethIoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import {GIVETH_TOKEN_DISTRO_ADDRESS} from "./subgraphService";
import TokenDistroJSON from '../abi/TokenDistroV2.json'
const Ethers = require("ethers");
const {isAddress} = require("ethers");

require('dotenv').config()

Expand Down Expand Up @@ -37,6 +38,19 @@ const gnosisProvider = new Ethers.JsonRpcProvider(xdaiNodeHttpUrl);
const tokenDistroGC = new Ethers.Contract(GIVETH_TOKEN_DISTRO_ADDRESS, TokenDistroJSON.abi, gnosisProvider);


export const isEvmAddress = (address: string): boolean => {
return isAddress(address);
};

const isStellarDonationAndUserLoggedInWithEvmAddress = (donation: GivethIoDonation): boolean => {
console.log('isStellarDonationAndUserLoggedIn', donation)
return Boolean (donation.transactionNetworkId === 1500 && donation?.user?.walletAddress && isEvmAddress(donation?.user?.walletAddress))
}

const donationGiverAddress = (donation: GivethIoDonation): string => {
return isStellarDonationAndUserLoggedInWithEvmAddress(donation) ? donation.user.walletAddress : donation.fromWalletAddress
}

/**
*
* @returns {Promise<[{amount:400, currency:"GIV",createdAt:"",
Expand Down Expand Up @@ -116,6 +130,7 @@ export const getEligibleDonations = async (
user {
name
email
walletAddress
}
fromWalletAddress
status
Expand All @@ -131,7 +146,7 @@ export const getEligibleDonations = async (
moment(donation.createdAt) < secondDate
&& moment(donation.createdAt) > firstDate
&& donation.valueUsd
&& donation.chainType == 'EVM'
&& (donation.chainType == 'EVM' || isStellarDonationAndUserLoggedInWithEvmAddress(donation) )
&& donation.isProjectVerified
&& donation.status === 'verified'
)
Expand All @@ -142,7 +157,7 @@ export const getEligibleDonations = async (
moment(donation.createdAt) < secondDate
&& moment(donation.createdAt) > firstDate
&& donation.valueUsd
&& donation.chainType == 'EVM'
&& (donation.chainType == 'EVM' || isStellarDonationAndUserLoggedInWithEvmAddress(donation) )
&& !donation.isProjectVerified
&& donation.status === 'verified'
)
Expand Down Expand Up @@ -201,7 +216,7 @@ export const getEligibleDonations = async (
usdValue: item.valueUsd,
givFactor: item.givbackFactor
}),
giverAddress: item.fromWalletAddress,
giverAddress: donationGiverAddress(item),
txHash: item.transactionId,
network: getNetworkNameById(item.transactionNetworkId),
source: 'giveth.io',
Expand Down Expand Up @@ -232,7 +247,7 @@ export const getEligibleDonations = async (
projectRank: item.projectRank,
bottomRankInRound: item.powerRound,
givbacksRound: item.powerRound,
giverAddress: item.fromWalletAddress,
giverAddress: donationGiverAddress(item),
txHash: item.transactionId,
network: getNetworkNameById(item.transactionNetworkId),
source: 'giveth.io',
Expand Down Expand Up @@ -313,7 +328,7 @@ export const getVerifiedPurpleListDonations = async (beginDate: string, endDate:
moment(donation.createdAt) < secondDate
&& moment(donation.createdAt) > firstDate
&& donation.valueUsd
&& donation.chainType == 'EVM'
&& (donation.chainType == 'EVM' || isStellarDonationAndUserLoggedInWithEvmAddress(donation) )
&& donation.isProjectVerified
&& donation.status === 'verified'
)
Expand All @@ -326,7 +341,7 @@ export const getVerifiedPurpleListDonations = async (beginDate: string, endDate:
createdAt: moment(item.createdAt).format('YYYY-MM-DD-hh:mm:ss'),
valueUsd: item.valueUsd,
givbackFactor: item.givbackFactor,
giverAddress: item.fromWalletAddress,
giverAddress: donationGiverAddress(item),
txHash: item.transactionId,
network: getNetworkNameById(item.transactionNetworkId),
source: 'giveth.io',
Expand Down
5 changes: 2 additions & 3 deletions src/types/general.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import moment from "moment";

export interface FormattedDonation {
amount: string,
currency: string,
Expand Down Expand Up @@ -47,7 +45,8 @@ export interface GivethIoDonation {
source: string,
user: {
name: string,
email: string
email: string,
walletAddress: string
}

recurringDonation ?: {
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,12 @@ export const getNetworkNameById = (networkId: number): string => {
return 'optimism'
case 420 :
return 'optimism-goerli'
case 11155420 :
return 'optimism-sepolia'
case 100 :
return 'gnosis'
case 1500 :
return 'stellar'
case 137:
return 'polygon'
case 42220:
Expand Down