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

Merge mip 118 #96

Merged
merged 42 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
623adc8
feat: Add Evm connector plugin - MEED-3205 - Meeds-io/MIPs#118 (#1)
MayTekayaa Feb 1, 2024
2f22083
feat: Automate the transfer meeds token rewarding - MEED-3293 - Meed…
MayTekayaa Feb 27, 2024
0ef0910
feat: Automate the transfer of any ERC20 token rewarding - MEED-3206 …
MayTekayaa Mar 8, 2024
dbb821d
feat: Recognize ERC20 token - MEED-3806 - Meeds-io/MIPs#118 (#10)
MayTekayaa Mar 14, 2024
3d075b9
fix: Fix the evm connector name - MEED-4283 - Meeds-io/MIPs#118 (#15)
MayTekayaa Mar 28, 2024
fe59bbf
fix: Fix the smart contract validation error - MEED-4306 - Meeds-io/M…
MayTekayaa Mar 29, 2024
fcf4408
feat: Select blockchain when only creating an action - MEED-4280 - M…
MayTekayaa Mar 21, 2024
7007934
feat: Automate the erc20 token transfers rewarding for any blockchain…
MayTekayaa Mar 28, 2024
1d69ca3
feat: Add some enhancements to the smart contract part - MEED-4314 - …
MayTekayaa Mar 29, 2024
ef10e8e
fix: Ability to connect only when the connector is active - MEED-5281…
AzmiTouil Apr 4, 2024
d8156e4
feat: Add a verify instruction for erc20 token - MEED-5280 - Meeds-…
MayTekayaa Apr 4, 2024
fbbb197
feat: Edit the smart contract address field - MEED-4303 - Meeds-io/M…
MayTekayaa Apr 8, 2024
6429e17
feat: Change the evm icon used - MEED-5032 - Meeds-io/MIPs#118 (#28)
MayTekayaa Apr 18, 2024
c1c05a8
feat: Add more filters for transfer tokens for the evm action - MEED-…
MayTekayaa Apr 18, 2024
200566f
feat: Improve the token name display - MEED-4311 - Meeds-io/MIPs#118 …
MayTekayaa Apr 24, 2024
0b0cb59
feat: Improve the display of selected blockchain in the EVM action dr…
MayTekayaa Apr 24, 2024
cc8f12c
feat: Rename the transfer EVM action event - MEED-6518 - Meeds-io/MIP…
MayTekayaa Apr 29, 2024
6ac6773
feat: Add receive token trigger for EVM action - MEED-6519 - Meeds-io…
MayTekayaa May 3, 2024
198f3cc
fix: Fix EVM Transaction Queue Processing - MEED-6897 - Meeds-io/MIPs…
boubaker May 23, 2024
a79f8e0
fix: Add Contract Filtering on Catched Transfer Event - MEED-6935 - M…
boubaker May 24, 2024
e903a60
feat: Enable the next button when no minAmount or sender/recipient en…
MayTekayaa May 31, 2024
64e272c
feat: Enable the update button when only edit an action - MEED-6690 -…
MayTekayaa Jun 3, 2024
2475a06
feat: Add a format check to the sender/ recipient address - MEED-6687…
MayTekayaa Jun 10, 2024
2b0fb29
feat: Use fontawesome icon for EVM connector - MEED-6877 - Meeds-io/M…
MayTekayaa Jun 14, 2024
6eec50d
feat: Validate contract with enter key - MEED-7025 - Meeds-io/MIPs#11…
MayTekayaa Jun 25, 2024
18a77d2
feat: Update wallet service dependency - MEED-7455 - Meeds-io/MIP#154…
AzmiTouil Oct 9, 2024
de2dc24
feat: Adjust the display of blockchain network - MEED-7676 - Meeds-io…
MayTekayaa Nov 28, 2024
48feff9
feat: Add hold token event for the EVM action - MEED-6663 - Meeds-io/…
MayTekayaa May 30, 2024
18b5767
feat: Handle the hold event when connecting a new wallet - MEED-7757 …
MayTekayaa Nov 19, 2024
8dfa3d0
feat: Handle the hold event when create or update an action - MEED-77…
MayTekayaa Nov 25, 2024
73b78a0
feat: Recognize token type - MEED-6688 - Meeds-io/MIPs#118 (#74)
MayTekayaa Dec 10, 2024
7f61c19
fix: Add contribution link to the achievements exported file - MEED-7…
AzmiTouil Dec 16, 2024
03396ea
feat: Refactor the code to be used for NFT tokens - MEED-7931 - Meeds…
MayTekayaa Jan 14, 2025
04ea6a7
feat: Fix the connection wallet listener - MEED-7963 - Meeds-io/MIPs#…
MayTekayaa Jan 16, 2025
3d78d6b
feat: Review the amount title for hold event - MEED-7179 - Meeds-io/M…
MayTekayaa Jan 15, 2025
bd3829a
fix: Fix of the transaction saving job to handle transactions that do…
MayTekayaa Jan 17, 2025
a0fd082
feat: Review the display of tokens when adding action - MEED-7134 - M…
MayTekayaa Jan 17, 2025
c18aff5
feat: Review the display of tokens when viewing action - MEED-7853 - …
MayTekayaa Jan 20, 2025
dd6ba3c
fix: Fix the connection wallet listener - MEED-7963 - Meeds-io/MIPs#1…
MayTekayaa Jan 21, 2025
5df9bb8
feat: Add the action label for evm connector - MEED-8212 - Meeds-io/M…
MayTekayaa Jan 21, 2025
1057603
feat: Add evm events description - MEED-8210 - Meeds-io/MIPs#118 (#94)
MayTekayaa Jan 21, 2025
dc46684
fix: Fix the send/ receive event - MEED-8220 - Meeds-io/MIPs#118 (#100)
MayTekayaa Jan 23, 2025
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
21 changes: 21 additions & 0 deletions gamification-evm-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@
<groupId>io.meeds.gamification</groupId>
<artifactId>gamification-services</artifactId>
</dependency>
<dependency>
<groupId>io.meeds.wallet</groupId>
<artifactId>wallet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.exoplatform.wallet</groupId>
<artifactId>ert-contract</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
</dependency>
</dependencies>
<build>
<finalName>gamification-evm-service</finalName>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2020 - 2024 Meeds Association contact@meeds.io
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.meeds.evm.gamification.blockchain;

import org.springframework.context.annotation.Configuration;

import org.web3j.protocol.Web3j;
import org.web3j.protocol.http.HttpService;

@Configuration
public class BlockchainConfiguration {

public Web3j getNetworkWeb3j(String networkUrl) {
return Web3j.build(new HttpService(networkUrl));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2020 - 2024 Meeds Association contact@meeds.io
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.meeds.evm.gamification.blockchain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "meeds.gamification.evm.blockchain")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BlockchainConfigurationProperties {

private String polygonNetworkUrl;

private String networkUrl;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2024 Meeds Association contact@meeds.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.meeds.evm.gamification.dao;

import io.meeds.evm.gamification.entity.EvmTransactionEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface EvmTransactionDAO extends JpaRepository<EvmTransactionEntity, Long> {

EvmTransactionEntity findTopByContractAddressAndNetworkIdAndFromAddressOrderByIdDesc(String contractAddress, Long networkId, String fromAddress);
@Query("""
SELECT DISTINCT fromAddress AS address FROM EvmTransaction tr
WHERE tr.contractAddress = ?1 AND tr.transactionDate >= ?2 AND tr.networkId = ?3
UNION
SELECT DISTINCT toAddress AS address FROM EvmTransaction tr
WHERE tr.contractAddress = ?1 AND tr.transactionDate >= ?2 AND tr.networkId = ?3
""")
List<String> findDistinctAddresses(String contractAddress, Long ruleCreationDate, Long networkId);

List<EvmTransactionEntity> findByContractAddressAndNetworkIdAndToAddressAndTransactionDateGreaterThan(String contractAddress,
Long networkId,
String toAddress,
Long transactionDate);

List<EvmTransactionEntity> findByContractAddressAndNetworkIdAndFromAddressAndTransactionDateGreaterThan(String contractAddress,
Long networkId,
String fromAddress,
Long transactionDate);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2024 Meeds Association contact@meeds.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.meeds.evm.gamification.entity;

import jakarta.persistence.*;
import lombok.Data;

import java.io.Serializable;
import java.math.BigInteger;

@Entity(name = "EvmTransaction")
@Table(name = "EVM_TRANSACTIONS")
@Data
public class EvmTransactionEntity implements Serializable {

@Id
@SequenceGenerator(name = "SEQ_EVM_TRANSACTIONS_ID", sequenceName = "SEQ_EVM_TRANSACTIONS_ID", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_EVM_TRANSACTIONS_ID")
@Column(name = "ID", nullable = false)
private Long id;

@Column(name = "TRANSACTION_HASH", nullable = false)
private String transactionHash;

@Column(name = "NETWORK_ID", nullable = false)
private Long networkId;

@Column(name = "FROM_ADDRESS", nullable = false)
private String fromAddress;

@Column(name = "TO_ADDRESS", nullable = false)
private String toAddress;

@Column(name = "CONTRACT_ADDRESS", nullable = false)
private String contractAddress;

@Column(name = "TRANSACTION_DATE", nullable = false)
private Long transactionDate;

@Column(name = "AMOUNT")
private BigInteger amount;

@Column(name = "TOKEN_ID")
private BigInteger tokenId;

@Column(name = "WALLET_BALANCE", nullable = false)
private BigInteger walletBalance;

@Column(name = "BLOCK_NUMBER", nullable = false)
private BigInteger blockNumber;

@Column(name = "BLOCK_HASH", nullable = false)
private String blockHash;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2020 - 2024 Meeds Association contact@meeds.io
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.meeds.evm.gamification.listener;

import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import io.meeds.wallet.model.Wallet;
import io.meeds.evm.gamification.model.EvmTransaction;
import io.meeds.evm.gamification.service.EvmBlockchainService;
import io.meeds.evm.gamification.service.EvmContractTransferService;
import io.meeds.evm.gamification.service.EvmTransactionService;
import io.meeds.evm.gamification.utils.Utils;
import io.meeds.gamification.model.RuleDTO;
import io.meeds.gamification.service.RuleService;
import io.meeds.wallet.service.WalletAccountService;

import org.exoplatform.commons.api.persistence.ExoTransactional;
import org.exoplatform.services.listener.Event;
import org.exoplatform.services.listener.Listener;
import org.exoplatform.services.listener.ListenerService;
import org.exoplatform.social.core.space.model.Space;
import org.exoplatform.social.core.space.spi.SpaceService;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static io.meeds.evm.gamification.utils.Utils.*;
import static io.meeds.gamification.utils.Utils.POST_CREATE_RULE_EVENT;
import static io.meeds.gamification.utils.Utils.POST_UPDATE_RULE_EVENT;
import static io.meeds.gamification.utils.Utils.getUserIdentity;

@Component
public class RuleCheckForHoldEventListener extends Listener<Long, String> {
private static final List<String> SUPPORTED_EVENTS = Arrays.asList(POST_CREATE_RULE_EVENT, POST_UPDATE_RULE_EVENT);

@Autowired
private ListenerService listenerService;

@Autowired
private RuleService ruleService;

@Autowired
private SpaceService spaceService;

@Autowired
private WalletAccountService walletAccountService;

@Autowired
private EvmBlockchainService evmBlockchainService;

@Autowired
private EvmTransactionService evmTransactionService;

@Autowired
private EvmContractTransferService evmContractTransferService;

@PostConstruct
public void init() {
for (String eventName : SUPPORTED_EVENTS) {
listenerService.addListener(eventName, this);
}
}

@Override
@ExoTransactional
public void onEvent(Event<Long, String> event) {
Long ruleId = event.getSource();
RuleDTO evmRule = ruleService.findRuleById(ruleId);
Boolean enabledProg = evmRule.getProgram().isEnabled();
String trigger = evmRule.getEvent().getTrigger();
if (enabledProg && trigger.equals(HOLD_TOKEN_EVENT)) {
Long spaceId = evmRule.getProgram().getSpaceId();
String contractAddress = evmRule.getEvent().getProperties().get(Utils.CONTRACT_ADDRESS).toLowerCase();
String blockchainNetwork = evmRule.getEvent().getProperties().get(Utils.BLOCKCHAIN_NETWORK);
Long networkId = Long.parseLong(evmRule.getEvent().getProperties().get(Utils.NETWORK_ID));
Long duration = Long.parseLong(evmRule.getEvent().getProperties().get(Utils.DURATION));
org.web3j.abi.datatypes.Event blockchainEvent;
if (evmBlockchainService.isERC1155(blockchainNetwork, contractAddress)) {
blockchainEvent = TRANSFERSINGLE_EVENT;
} else if (evmBlockchainService.isERC721(blockchainNetwork, contractAddress)) {
blockchainEvent = TRANSFER_EVENT_ER721;
} else {
blockchainEvent = TRANSFER_EVENT_ERC20;
}
if (spaceId == 0) {
Set<Wallet> wallets = walletAccountService.listWallets();
List<String> walletsAddresses = wallets.stream().map(Wallet::getAddress).collect(Collectors.toList());
walletsAddresses.forEach(walletAddress -> {
if (event.getEventName().equals(POST_CREATE_RULE_EVENT)) {
evmContractTransferService.handleHoldEvent(blockchainNetwork,
contractAddress,
walletAddress,
networkId,
duration,
evmRule,
blockchainEvent,
trigger,
null);

} else if (event.getEventName().equals(POST_UPDATE_RULE_EVENT)) {
evmContractTransferService.saveLastRewardTime(walletAddress, evmRule.getId());
}
});

} else {
Space space = spaceService.getSpaceById(String.valueOf(spaceId));
String[] members = space.getMembers();
Arrays.stream(members).forEach(member -> {
Long identityId = Long.parseLong(getUserIdentity(member).getId());
String walletAddress = walletAccountService.getWalletByIdentityId(identityId).getAddress();
if (event.getEventName().equals(POST_CREATE_RULE_EVENT)) {
evmContractTransferService.handleHoldEvent(blockchainNetwork,
contractAddress,
walletAddress,
networkId,
duration,
evmRule,
blockchainEvent,
trigger,
null);
} else if (event.getEventName().equals(POST_UPDATE_RULE_EVENT)) {
evmContractTransferService.saveLastRewardTime(walletAddress, evmRule.getId());
}
});
}
}
}
}
Loading
Loading