From 003c4519129e3a8bc4841f33426d347449838bf9 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Fri, 26 Jul 2024 13:58:17 +0800 Subject: [PATCH] envio service file --- apollo/src/lnv3/source/envio.service.ts | 87 +++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 apollo/src/lnv3/source/envio.service.ts diff --git a/apollo/src/lnv3/source/envio.service.ts b/apollo/src/lnv3/source/envio.service.ts new file mode 100644 index 0000000..6118654 --- /dev/null +++ b/apollo/src/lnv3/source/envio.service.ts @@ -0,0 +1,87 @@ +import axios from 'axios'; +import { + Lnv3Record, + Lnv3UpdateRecords, + Lnv3RelayRecord, + Lnv3WithdrawStatus, + SourceService, +} from './source.service'; + +export class Lnv3EnvioService extends SourceService { + async queryRecordInfo(url: string, chainId: number, latestNonce: number): Promise { + const query = `query { Lnv3TransferRecord(limit: 20, order_by: { nonce: asc }, offset: ${latestNonce}, where: {localChainId: {_eq: ${chainId}}}) { id, nonce, messageNonce, remoteChainId, provider, sourceToken, targetToken, sourceAmount, targetAmount, sender, receiver, timestamp, transactionHash, fee, transferId, hasWithdrawn } }`; + return await axios + .post(url, { + query: query, + variables: null, + }) + .then((res) => res.data?.data?.Lnv3TransferRecord); + } + + async queryProviderInfo( + url: string, + chainId: number, + latestNonce: number + ): Promise { + const query = `query { Lnv3RelayUpdateRecord(limit: 20, order_by: { nonce: asc }, offset: ${latestNonce}, where: {localChainId: {_eq: ${chainId}}}) { id, updateType, remoteChainId, provider, transactionHash, timestamp, sourceToken, targetToken, penalty, baseFee, liquidityFeeRate, transferLimit, paused } }`; + return await axios + .post(url, { + query: query, + variables: null, + }) + .then((res) => res.data?.data?.Lnv3RelayUpdateRecord); + } + async queryRelayStatus( + url: string, + chainId: number, + transferId: string + ): Promise { + const query = `query { Lnv3RelayRecord(where: { id: { _eq: "${transferId}" }, localChainId: {_eq: ${chainId}}}) { id, relayer, timestamp, transactionHash, slashed, requestWithdrawTimestamp, fee }}`; + return await axios + .post(url, { + query: query, + variables: null, + }) + .then((res) => res.data?.data?.Lnv3RelayRecord?.[0]); + } + async queryMultiRelayStatus( + url: string, + chainId: number, + transferIds: string[] + ): Promise { + const idArray = '["' + transferIds.join('","') + '"]'; + const query = `query { Lnv3RelayRecord(limit: 20, where: {id: { _in: ${idArray}}, localChainId: {_eq: ${chainId}}}) { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }`; + return await axios + .post(url, { + query: query, + variables: null, + }) + .then((res) => res.data?.data?.Lnv3RelayRecord); + } + async batchQueryRelayStatus( + url: string, + chainId: number, + latestTimestamp: number + ): Promise { + const query = `query { Lnv3RelayRecord(limit: 20, order_by: { timestamp: asc }, where: { timestamp: { _gt: ${latestTimestamp}}, localChainId: {_eq: ${chainId}}, slashed: { _eq: false }}) { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }`; + return await axios + .post(url, { + query: query, + variables: null, + }) + .then((res) => res.data?.data?.Lnv3RelayRecord); + } + async queryWithdrawStatus( + url: string, + chainId: number, + transferId: string + ): Promise { + const query = `query { Lnv3TransferRecord(where: { id: { _eq: "${transferId}" }, localChainId: {_eq: ${chainId}}}) { id, hasWithdrawn }}`; + return await axios + .post(url, { + query: query, + variables: null, + }) + .then((res) => res.data?.data?.Lnv3TransferRecord); + } +}