Skip to content

Commit

Permalink
envio service file
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Jul 26, 2024
1 parent ef0f46e commit 003c451
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions apollo/src/lnv3/source/envio.service.ts
Original file line number Diff line number Diff line change
@@ -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<Lnv3Record[]> {
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<Lnv3UpdateRecords[]> {
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<Lnv3RelayRecord> {
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<Lnv3RelayRecord[]> {
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<Lnv3RelayRecord[]> {
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<Lnv3WithdrawStatus> {
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);
}
}

0 comments on commit 003c451

Please sign in to comment.