From 084e57e96ee99472b645f0b46a2ccaf6729316bc Mon Sep 17 00:00:00 2001 From: LayneHaber Date: Tue, 14 Jun 2022 15:08:21 -0600 Subject: [PATCH 1/2] only update if not reconciled --- .../src/amarok-runtime-staging/mapping.ts | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/packages/deployments/subgraph/src/amarok-runtime-staging/mapping.ts b/packages/deployments/subgraph/src/amarok-runtime-staging/mapping.ts index e36ab54d22..07739b52e2 100644 --- a/packages/deployments/subgraph/src/amarok-runtime-staging/mapping.ts +++ b/packages/deployments/subgraph/src/amarok-runtime-staging/mapping.ts @@ -239,33 +239,36 @@ export function handleXCalled(event: XCalled): void { * @param event - The contract event used to update the subgraph */ export function handleExecuted(event: Executed): void { - const num = event.params.args.routers.length; - const amount = event.params.args.amount; - const routers: string[] = []; - for (let i = 0; i < num; i++) { - const param = event.params.args.routers[i].toHex(); - let router = Router.load(param); - if (router == null) { - // TODO: Shouldn't we be throwing an error here? How did a transfer get made with a non-existent - // router? - router = new Router(param); - router.isActive = true; - router.save(); - } - - routers.push(router.id); - - // Update router's liquidity - const assetBalance = getOrCreateAssetBalance(event.params.args.local, event.params.args.routers[i]); - assetBalance.amount = assetBalance.amount.minus(amount.div(BigInt.fromI32(num))); - assetBalance.save(); - } - + // Load transfer details let transfer = DestinationTransfer.load(event.params.transferId.toHexString()); if (transfer == null) { transfer = new DestinationTransfer(event.params.transferId.toHexString()); } + const num = event.params.args.routers.length; + const amount = event.params.args.amount; + const routers: string[] = []; + if (transfer.status != "Reconciled") { + for (let i = 0; i < num; i++) { + const param = event.params.args.routers[i].toHex(); + let router = Router.load(param); + if (router == null) { + // TODO: Shouldn't we be throwing an error here? How did a transfer get made with a non-existent + // router? + router = new Router(param); + router.isActive = true; + router.save(); + } + + routers.push(router.id); + + // Update router's liquidity + const assetBalance = getOrCreateAssetBalance(event.params.args.local, event.params.args.routers[i]); + assetBalance.amount = assetBalance.amount.minus(amount.div(BigInt.fromI32(num))); + assetBalance.save(); + } + } // otherwise no routers used + // Meta transfer.chainId = getChainId(); transfer.transferId = event.params.transferId; @@ -369,9 +372,11 @@ export function handleReconciled(event: Reconciled): void { transfer.save(); } +// eslint-disable-next-line @typescript-eslint/ban-types function getChainId(): BigInt { // try to get chainId from the mapping let network = dataSource.network(); + // eslint-disable-next-line @typescript-eslint/ban-types let chainId: BigInt; if (network == "mainnet") { chainId = BigInt.fromI32(1); From d7d500e0c5f987e4cced08b1aac305f240bc42ce Mon Sep 17 00:00:00 2001 From: LayneHaber Date: Tue, 14 Jun 2022 17:22:07 -0600 Subject: [PATCH 2/2] update runtime --- .../subgraph/src/amarok-runtime-v0/mapping.ts | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/packages/deployments/subgraph/src/amarok-runtime-v0/mapping.ts b/packages/deployments/subgraph/src/amarok-runtime-v0/mapping.ts index e36ab54d22..7080c958ca 100644 --- a/packages/deployments/subgraph/src/amarok-runtime-v0/mapping.ts +++ b/packages/deployments/subgraph/src/amarok-runtime-v0/mapping.ts @@ -239,32 +239,36 @@ export function handleXCalled(event: XCalled): void { * @param event - The contract event used to update the subgraph */ export function handleExecuted(event: Executed): void { + // Load transfer details + let transfer = DestinationTransfer.load(event.params.transferId.toHexString()); + if (transfer == null) { + transfer = new DestinationTransfer(event.params.transferId.toHexString()); + } + const num = event.params.args.routers.length; const amount = event.params.args.amount; const routers: string[] = []; - for (let i = 0; i < num; i++) { - const param = event.params.args.routers[i].toHex(); - let router = Router.load(param); - if (router == null) { - // TODO: Shouldn't we be throwing an error here? How did a transfer get made with a non-existent - // router? - router = new Router(param); - router.isActive = true; - router.save(); - } - routers.push(router.id); + if (transfer.status != "Reconciled") { + for (let i = 0; i < num; i++) { + const param = event.params.args.routers[i].toHex(); + let router = Router.load(param); + if (router == null) { + // TODO: Shouldn't we be throwing an error here? How did a transfer get made with a non-existent + // router? + router = new Router(param); + router.isActive = true; + router.save(); + } - // Update router's liquidity - const assetBalance = getOrCreateAssetBalance(event.params.args.local, event.params.args.routers[i]); - assetBalance.amount = assetBalance.amount.minus(amount.div(BigInt.fromI32(num))); - assetBalance.save(); - } + routers.push(router.id); - let transfer = DestinationTransfer.load(event.params.transferId.toHexString()); - if (transfer == null) { - transfer = new DestinationTransfer(event.params.transferId.toHexString()); - } + // Update router's liquidity + const assetBalance = getOrCreateAssetBalance(event.params.args.local, event.params.args.routers[i]); + assetBalance.amount = assetBalance.amount.minus(amount.div(BigInt.fromI32(num))); + assetBalance.save(); + } + } // otherwise no routers used // Meta transfer.chainId = getChainId(); @@ -369,9 +373,11 @@ export function handleReconciled(event: Reconciled): void { transfer.save(); } +// eslint-disable-next-line @typescript-eslint/ban-types function getChainId(): BigInt { // try to get chainId from the mapping let network = dataSource.network(); + // eslint-disable-next-line @typescript-eslint/ban-types let chainId: BigInt; if (network == "mainnet") { chainId = BigInt.fromI32(1);