Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ model Transfer {
toDomainId Int?
destination String?
amount String?
securityModel Int?
status TransferStatus
deposit Deposit?
execution Execution?
Expand Down Expand Up @@ -71,7 +72,6 @@ model Deposit {
blockNumber String
depositData String
timestamp DateTime?
handlerResponse String
}

model Execution {
Expand Down
14 changes: 11 additions & 3 deletions src/indexer/repository/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type TransferMetadata = {
fromDomainId: string
toDomainId: string
resourceID: string
securityModel: number
timestamp: Date
deposit: Deposit
resource: {
Expand Down Expand Up @@ -69,6 +70,7 @@ class TransferRepository {
},
},
usdValue: decodedLog.usdValue,
securityModel: decodedLog.securityModel,
}

return await this.transfer.upsert({
Expand Down Expand Up @@ -102,7 +104,7 @@ class TransferRepository {
public async insertSubstrateDepositTransfer(
substrateDepositData: Pick<
DecodedDepositLog,
"depositNonce" | "sender" | "amount" | "destination" | "resourceID" | "toDomainId" | "fromDomainId"
"depositNonce" | "sender" | "amount" | "destination" | "resourceID" | "toDomainId" | "fromDomainId" | "securityModel"
> & { usdValue: number },
): Promise<Transfer> {
const transferData = {
Expand Down Expand Up @@ -133,6 +135,7 @@ class TransferRepository {
},
},
usdValue: substrateDepositData.usdValue,
securityModel: substrateDepositData.securityModel || 1,
}

return await this.transfer.create({ data: transferData })
Expand Down Expand Up @@ -198,7 +201,11 @@ class TransferRepository {
toDomainId,
sender,
usdValue,
}: Pick<DecodedDepositLog, "depositNonce" | "sender" | "amount" | "destination" | "resourceID" | "fromDomainId" | "toDomainId"> & {
securityModel,
}: Pick<
DecodedDepositLog,
"depositNonce" | "sender" | "amount" | "destination" | "resourceID" | "fromDomainId" | "toDomainId" | "securityModel"
> & {
usdValue: number | null
},
id: string,
Expand Down Expand Up @@ -228,7 +235,8 @@ class TransferRepository {
},
},
usdValue: usdValue,
} as Pick<TransferMetadata, "depositNonce" | "amount" | "destination" | "resource" | "fromDomain" | "toDomain" | "account">
securityModel: securityModel,
} as Pick<TransferMetadata, "depositNonce" | "amount" | "destination" | "resource" | "fromDomain" | "toDomain" | "account" | "securityModel">
return await this.transfer.update({ where: { id: id }, data: transferData })
}

Expand Down
2 changes: 1 addition & 1 deletion src/indexer/services/evmIndexer/evmTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type DecodedDepositLog = {
txHash: string
timestamp: number
depositData: string
handlerResponse: string
securityModel: number
transferType: string
amount: string
senderStatus?: string
Expand Down
10 changes: 5 additions & 5 deletions src/indexer/services/substrateIndexer/substrateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SPDX-License-Identifier: LGPL-3.0-only
*/
import { XcmAssetId } from "@polkadot/types/interfaces"

export type RawProposalExecutionData = { originDomainId: string; depositNonce: string; dataHash: string }
export type RawProposalExecutionData = { originDomainId: string; depositNonce: string }

export type RawDepositData = {
destDomainId: string
Expand All @@ -13,7 +13,7 @@ export type RawDepositData = {
sender: string
transferType: string
depositData: string
handlerResponse: string
securityModel: number
}

export type RawFeeCollectedData = {
Expand All @@ -24,9 +24,9 @@ export type RawFeeCollectedData = {
feeAssetId: XcmAssetId
}

export type RawFailedHandlerExecutionData = Omit<RawProposalExecutionData, "dataHash"> & { error: string }
export type RawFailedHandlerExecutionData = RawProposalExecutionData & { error: string }

export type ProposalExecutionDataToSave = Omit<RawProposalExecutionData, "dataHash"> & {
export type ProposalExecutionDataToSave = RawProposalExecutionData & {
txIdentifier: string
blockNumber: string
timestamp: number
Expand All @@ -36,7 +36,7 @@ export type FeeCollectedDataToSave = RawFeeCollectedData & {
txIdentifier: string
}

export type FailedHandlerExecutionToSave = Omit<RawProposalExecutionData, "dataHash"> & {
export type FailedHandlerExecutionToSave = RawProposalExecutionData & {
error: string
txIdentifier: string
blockNumber: string
Expand Down
3 changes: 1 addition & 2 deletions src/indexer/utils/evm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export async function parseDeposit(
txHash: log.transactionHash,
timestamp: blockUnixTimestamp,
depositData: decodedLog.args.data as string,
handlerResponse: decodedLog.args.handlerResponse as string,
securityModel: (decodedLog.args.securityModel as number) || 1,
transferType: resourceType,
amount: decodeAmountsOrTokenId(decodedLog.args.data as string, resourceDecimals, resourceType) as string,
fee: await getFee(provider, fromDomain.feeRouter, fromDomain, decodedLog),
Expand Down Expand Up @@ -315,7 +315,6 @@ export async function saveDepositLogs(
blockNumber: decodedLog.blockNumber.toString(),
depositData: decodedLog.depositData,
timestamp: new Date(decodedLog.timestamp * 1000),
handlerResponse: decodedLog.handlerResponse,
transferId: transfer.id,
}
const depositExists = await depositRepository.findDeposit(transfer.id)
Expand Down
12 changes: 6 additions & 6 deletions src/indexer/utils/substrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ export async function saveDeposit(
txIdentifier,
blockNumber,
depositData,
handlerResponse,
sender,
resourceId,
timestamp,
securityModel,
} = substrateDepositData

const currentDomain = sharedConfig.domains.find(domain => domain.id === originDomainId)
Expand Down Expand Up @@ -147,7 +147,7 @@ export async function saveDeposit(
destination: `0x${depositData.substring(2).slice(128, depositData.length - 1)}`,
} as Pick<
DecodedDepositLog,
"depositNonce" | "amount" | "destination" | "resourceID" | "toDomainId" | "fromDomainId" | "timestamp" | "sender"
"depositNonce" | "amount" | "destination" | "resourceID" | "toDomainId" | "fromDomainId" | "timestamp" | "sender" | "securityModel"
> & { usdValue: number }

if (transfer.accountId !== null) {
Expand Down Expand Up @@ -177,9 +177,10 @@ export async function saveDeposit(
timestamp: timestamp,
destination: `0x${depositData.substring(2).slice(128, depositData.length - 1)}`,
usdValue: amountInUSD,
securityModel: securityModel,
} as Pick<
DecodedDepositLog,
"depositNonce" | "sender" | "amount" | "destination" | "resourceID" | "toDomainId" | "fromDomainId" | "timestamp"
"depositNonce" | "sender" | "amount" | "destination" | "resourceID" | "toDomainId" | "fromDomainId" | "timestamp" | "securityModel"
> & { usdValue: number }

await accountRepository.insertAccount({ id: sender, addressStatus: "" })
Expand All @@ -194,7 +195,6 @@ export async function saveDeposit(
blockNumber: blockNumber,
depositData: depositData,
timestamp: new Date(timestamp),
handlerResponse: handlerResponse,
transferId: transfer.id,
}
await depositRepository.insertDeposit(deposit)
Expand Down Expand Up @@ -273,7 +273,7 @@ export async function saveEvents(
for (const depositEvent of depositEvents) {
const txIdentifier = `${block}-${depositEvent.phase.asApplyExtrinsic}` //this is like the txHash but for the substrate
const { data } = depositEvent.event.toHuman()
const { destDomainId, resourceId, depositNonce, sender, transferType, depositData, handlerResponse } = data
const { destDomainId, resourceId, depositNonce, sender, transferType, depositData, securityModel } = data
await saveDepositToDb(
domain,
block.toString(),
Expand All @@ -284,10 +284,10 @@ export async function saveEvents(
sender,
transferType,
depositData,
handlerResponse,
txIdentifier,
blockNumber: `${block}`,
timestamp,
securityModel: securityModel,
},
transferRepository,
depositRepository,
Expand Down
1 change: 0 additions & 1 deletion src/interfaces/TransfersInterfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export type IncludedQueryParams = {
txHash: boolean
blockNumber: boolean
depositData: boolean
handlerResponse: boolean
timestamp: boolean
}
}
Expand Down
1 change: 1 addition & 0 deletions src/scripts/classes/PriceCalculation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class PriceCalculation implements IFixInterface {
sender: transfer.accountId!,
toDomainId: String(transfer.toDomainId!),
usdValue: newValue,
securityModel: transfer.securityModel!,
},
transfer.id,
)
Expand Down
4 changes: 1 addition & 3 deletions src/seed/seeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const seeder = async (): Promise<void> => {
console.log(`Adding ${domainsWithRpcURL.length} domains`)

for (const pl of onlyTokensTransfers) {
const { destinationDomainID, resourceID, depositNonce, user, data, handlerResponse } = pl.parsedData.args
const { destinationDomainID, resourceID, depositNonce, user, data} = pl.parsedData.args
const { txHash, blockNumber } = pl

const destinationDomain = domainsWithRpcURL.find(domain => domain.id === destinationDomainID)
Expand Down Expand Up @@ -177,7 +177,6 @@ const seeder = async (): Promise<void> => {
txHash,
blockNumber,
depositData: data as string,
handlerResponse: handlerResponse as string,
},
execution: {
txHash,
Expand Down Expand Up @@ -222,7 +221,6 @@ const seeder = async (): Promise<void> => {
txHash: augmentedTransfer.deposit.txHash,
blockNumber: `${augmentedTransfer.deposit.blockNumber}`,
depositData: augmentedTransfer.deposit.depositData,
handlerResponse: augmentedTransfer.deposit.handlerResponse,
},
},
execution: {
Expand Down
14 changes: 1 addition & 13 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
The Licensed Work is (c) 2023 Sygma
SPDX-License-Identifier: LGPL-3.0-only
*/
import { Signer, ethers, AbiCoder } from "ethers"
import { Signer, ethers } from "ethers"
import { ERC20Handler__factory as Erc20HandlerFactory, ERC721Handler__factory as Erc721HandlerFactory } from "@buildwithsygma/sygma-contracts"
import { sleep } from "../indexer/utils/substrate"
import { EvmBridgeConfig, HandlersMap, SygmaConfig } from "../sygmaTypes"
Expand All @@ -12,17 +12,6 @@ export function getNetworkName(domainId: number, sygmaConfig: SygmaConfig): stri
return sygmaConfig.chains.find(c => c.domainId === domainId)?.name || ""
}

export function decodeDataHash(data: string): { amount: string; destinationRecipientAddress: string } {
const abiCoder = AbiCoder.defaultAbiCoder()
const decodedData = abiCoder.decode(["uint", "uint"], data)
const destinationRecipientAddressLen = Number(decodedData.toArray()[1]) * 2 // adjusted for bytes
const result = {
amount: `${decodedData.toArray()[0] as string}`,
destinationRecipientAddress: `0x${data.slice(130, 130 + destinationRecipientAddressLen)}`,
}
return result
}

export function convertMillisecondsToMinutes(duration: number): number {
return duration / 1000 / 60
}
Expand Down Expand Up @@ -70,7 +59,6 @@ export const getTransferQueryParams = (): IncludedQueryParams => {
txHash: true,
blockNumber: true,
depositData: true,
handlerResponse: true,
timestamp: true,
},
},
Expand Down
15 changes: 4 additions & 11 deletions swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ paths:
txHash: "0x0a457e0c76dc5945466c0f0f2bb6c39f5e5be5f48323fa29ec02295b5df4de4d"
blockNumber: "12984723"
depositData: "0x0000000000000000000000000000000000000000000000000000000000000001"
handlerResponse: "0x436f6e76657274696e6720726573706f6e73652066726f6d2068616e646c6572"
fee:
id: 60f7da143ce83aef2d325dd3
amount: 500000000000000000
Expand Down Expand Up @@ -148,7 +147,6 @@ paths:
txHash: "0x0a457e0c76dc5945466c0f0f2bb6c39f5e5be5f48323fa29ec02295b5df4de4d"
blockNumber: "12984723"
depositData: "0x0000000000000000000000000000000000000000000000000000000000000001"
handlerResponse: "0x8f7a67e5b31c7a259098b8c760f5a3f1e8102aa615fe5db5d86de18d52c5a5a5"
fee:
id: 61a4f4c2ab4d8145c6db5f09
amount: 1000000000000000000
Expand Down Expand Up @@ -448,6 +446,9 @@ components:
destination:
type: string
example: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
securityModel:
type: integer
example: 1

TransferStatus:
type: string
Expand Down Expand Up @@ -527,10 +528,6 @@ components:
depositData:
type: string
example: "0x1234567890abcdef"
handlerResponse:
type: string
nullable: true
example: "0x1234567890abcdef"

Execution:
type: object
Expand All @@ -556,8 +553,4 @@ components:
handlerResponse:
type: string
nullable: true
example: "0x1234567890abcdef"
dataHash:
type: string
nullable: true
example: "0x9876543210abcdef"
example: "0x1234567890abcdef"
4 changes: 2 additions & 2 deletions tests/e2e/domainAndResourceRoute.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe("Get all transfers for a specific resource between source and destinati
},
toDomain: { name: "evm2", lastIndexedBlock: transfers[0].toDomain.lastIndexedBlock, id: 2 },
fromDomain: { name: "Ethereum 1", lastIndexedBlock: transfers[0].fromDomain.lastIndexedBlock, id: 1 },
securityModel: 1,
fee: {
id: transfers[0].fee.id,
transferId: transfers[0].id,
Expand All @@ -104,7 +105,6 @@ describe("Get all transfers for a specific resource between source and destinati
blockNumber: "591",
depositData:
"0x0000000000000000000000000000000000000000000000001fdd50eb1da26c1000000000000000000000000000000000000000000000000000000000000000148e0a907331554af72563bd8d43051c2e64be5d35000000000000000000000000000000000000000000000000000000000000000c6d657461646174612e75726c",
handlerResponse: "0x6d657461646174612e746573746d657461646174612e75726c",
timestamp: "2023-07-17T08:31:22.000Z",
},
execution: {
Expand Down Expand Up @@ -145,6 +145,7 @@ describe("Get all transfers for a specific resource between source and destinati
},
toDomain: { name: "evm2", lastIndexedBlock: transfers[0].toDomain.lastIndexedBlock, id: 2 },
fromDomain: { name: "Ethereum 1", lastIndexedBlock: transfers[0].fromDomain.lastIndexedBlock, id: 1 },
securityModel: 1,
fee: {
amount: "1000000000000000",
id: transfers[0].fee.id,
Expand All @@ -163,7 +164,6 @@ describe("Get all transfers for a specific resource between source and destinati
blockNumber: "623",
depositData:
"0x0000000000000000000000000000000000000000000000000000000000030d400004ea287d1514b1387b365ae7294ea13bad9db83436e671dd16ba145c1f5961696bad2e73f73417f07ef55c62a2dc5b47ed248f568cc8f9fe4371a1d1fab88a62af595f8efb9aeff6f0e043b7ea33b10000000000000000000000005c1f5961696bad2e73f73417f07ef55c62a2dc5b",
handlerResponse: "0x",
timestamp: "2023-07-17T08:32:27.000Z",
},
execution: {
Expand Down
Loading