Skip to content
Merged
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
53 changes: 27 additions & 26 deletions claimer/src/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import { OriginNetworkConfig } from '@relay-vaults/types'
import { logger } from './logger'

const ENDPOINT = 'https://api.relay.link'
const TESTNETS_ENDPOINT = 'https://api.testnets.relay.link'
if (!process.env.RELAY_API_ENDPOINT) {
throw new Error('RELAY_API_ENDPOINT environment variable is not set')
}

interface BridgeTransaction {
amount: string
Expand All @@ -15,7 +16,7 @@
originTimestamp: number
}

const sendRequest = async (endpoint: string, body: any) => {

Check warning on line 19 in claimer/src/relay.ts

View workflow job for this annotation

GitHub Actions / Run tests - claimer

Unexpected any. Specify a different type
const response = await fetch(endpoint, {
body: JSON.stringify(body),
headers: {
Expand Down Expand Up @@ -55,16 +56,17 @@
logger.info(
`Submitting proof after ${after(bridgeTransaction.originTimestamp)} for ${bridgeTransaction.originTxHash} on ${originNetwork.name}`
)
const network = networks[bridgeTransaction.destinationPoolChainId]
const endpoint = network.isTestnet ? TESTNETS_ENDPOINT : ENDPOINT
await sendRequest(`${endpoint}/admin/execute-withdrawal`, {
amount: bridgeTransaction.amount,
currencyId: bridgeTransaction.asset === ZeroAddress ? 'eth' : 'erc20',
needsProving: true,
originChainId: bridgeTransaction.originChainId,
stack: originNetwork.stack,
txHash: bridgeTransaction.originTxHash,
})
await sendRequest(
`${process.env.RELAY_API_ENDPOINT}/admin/execute-withdrawal`,
{
amount: bridgeTransaction.amount,
currencyId: bridgeTransaction.asset === ZeroAddress ? 'eth' : 'erc20',
needsProving: true,
originChainId: bridgeTransaction.originChainId,
stack: originNetwork.stack,
txHash: bridgeTransaction.originTxHash,
}
)
}

// Finalize the withdrawal (after 7 days)
Expand All @@ -77,17 +79,18 @@
logger.info(
`Finalizing ${bridgeTransaction.originTxHash} on ${stack} after ${after(bridgeTransaction.originTimestamp)}`
)
const network = networks[bridgeTransaction.destinationPoolChainId]
const endpoint = network.isTestnet ? TESTNETS_ENDPOINT : ENDPOINT
await sendRequest(`${endpoint}/admin/execute-withdrawal`, {
amount: bridgeTransaction.amount,
currencyId: bridgeTransaction.asset === ZeroAddress ? 'eth' : 'erc20',
needsProving: false,
originChainId: bridgeTransaction.originChainId,
proveTxHash: bridgeTransaction.opProofTxHash,
stack: stack,
txHash: bridgeTransaction.originTxHash,
})
await sendRequest(
`${process.env.RELAY_API_ENDPOINT}/admin/execute-withdrawal`,
{
amount: bridgeTransaction.amount,
currencyId: bridgeTransaction.asset === ZeroAddress ? 'eth' : 'erc20',
needsProving: false,
originChainId: bridgeTransaction.originChainId,
proveTxHash: bridgeTransaction.opProofTxHash,
stack: stack,
txHash: bridgeTransaction.originTxHash,
}
)
}

export const claimFunds = async (
Expand All @@ -96,9 +99,7 @@
originChainId: number,
originBridgeAddress: string
) => {
const network = networks[chainId]
const endpoint = network.isTestnet ? TESTNETS_ENDPOINT : ENDPOINT
await sendRequest(`${endpoint}/admin/vault-claim`, {
await sendRequest(`${process.env.RELAY_API_ENDPOINT}/admin/vault-claim`, {
chainId,
originBridgeAddress,
originChainId,
Expand Down