Skip to content

Commit

Permalink
fix(api): simulating transaction proposal with transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
hbriese committed Nov 29, 2023
1 parent 7b68870 commit 05aeb62
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
3 changes: 1 addition & 2 deletions api/src/features/operations/operations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Operation,
PolicyKey,
Selector,
ZERO_ADDR,
asSelector,
isPresent,
tryOrIgnore,
Expand Down Expand Up @@ -87,7 +86,7 @@ export class OperationsService {
return Object.assign(new TransferOp(), {
_name: 'transfer',
_args: [to, value],
token: ZERO_ADDR,
token: ETH_ADDRESS,
to,
amount: value,
} satisfies TransferOp);
Expand Down
17 changes: 9 additions & 8 deletions api/src/features/simulations/simulations.processor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BullModuleOptions, InjectQueue, Process, Processor } from '@nestjs/bull';
import { Injectable, OnModuleInit } from '@nestjs/common';
import { Job, Queue } from 'bull';
import { Hex, ZERO_ADDR, asAddress, asHex, asUAddress } from 'lib';
import { ETH_ADDRESS, Hex, asAddress, asChain, asHex, asUAddress } from 'lib';
import { DatabaseService } from '../database/database.service';
import e from '~/edgeql-js';
import { and } from '../database/database.util';
Expand Down Expand Up @@ -64,16 +64,17 @@ export class SimulationsProcessor implements OnModuleInit {

const accountUAddress = asUAddress(p.account.address);
const accountAddress = asAddress(accountUAddress);
const chain = asChain(accountUAddress);
const account = selectAccount(accountUAddress);
const transfers: TransferDetails[] = [];

const transfers: TransferDetails[] = [];
for (const op of p.operations) {
if (op.value) {
transfers.push({
account,
from: accountAddress,
to: op.to,
tokenAddress: ZERO_ADDR,
tokenAddress: asUAddress(ETH_ADDRESS, chain),
amount: op.to === accountAddress ? 0n : -op.value,
direction: ['Out' as const, ...(op.to === accountAddress ? (['In'] as const) : [])],
});
Expand All @@ -84,12 +85,12 @@ export class SimulationsProcessor implements OnModuleInit {
value: op.value || undefined,
data: asHex(op.data || undefined),
});
if (f instanceof TransferOp && f.token !== ZERO_ADDR) {
if (f instanceof TransferOp && f.token !== ETH_ADDRESS) {
transfers.push({
account,
from: accountAddress,
to: f.to,
tokenAddress: f.token,
tokenAddress: asUAddress(f.token, chain),
amount: f.to === accountAddress ? 0n : -f.amount,
direction: ['Out' as const, ...(accountAddress === f.to ? (['In'] as const) : [])],
});
Expand All @@ -98,7 +99,7 @@ export class SimulationsProcessor implements OnModuleInit {
account,
from: f.from,
to: f.to,
tokenAddress: f.token,
tokenAddress: asUAddress(f.token, chain),
amount: f.amount,
direction: ['Out' as const, ...(accountAddress === f.to ? (['In'] as const) : [])],
});
Expand All @@ -107,7 +108,7 @@ export class SimulationsProcessor implements OnModuleInit {
account,
from: op.to,
to: accountAddress,
tokenAddress: f.toToken,
tokenAddress: asUAddress(f.toToken, chain),
amount: f.minimumToAmount,
direction: ['In' as const],
});
Expand Down Expand Up @@ -145,7 +146,7 @@ export class SimulationsProcessor implements OnModuleInit {

if (orphanedProposals.length) {
await this.queue.addBulk(
orphanedProposals.map((hash) => ({ data: { transactionProposalHash: hash as Hex } })),
orphanedProposals.map((hash) => ({ data: { transactionProposalHash: asHex(hash) } })),
);
}
}
Expand Down

0 comments on commit 05aeb62

Please sign in to comment.