Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update reservoir destination #354

Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions src/contextualizers/bridges/reservoir/destination.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { detect, generate } from './destination';
import { containsBigInt, contextSummary } from '../../../helpers/utils';
import bridgeZoraEnergyDestination0x7e7843df from '../../test/transactions/bridgeZoraEnergyDestination-0x7e7843df.json';
import bridgeZoraEnergyDestination0x1edd564e from '../../test/transactions/bridgeZoraEnergyDestination-0x1edd564e.json';
import bridgeZoraEnergyDestination0xf178e44b from '../../test/transactions/bridgeZoraEnergyDestination-0xf178e44b.json';
import hopDestination0x0902ccb6 from '../../test/transactions/hop-destination-0x0902ccb6.json';

describe('Bridge Zora Energy Destination', () => {
Expand All @@ -21,6 +22,11 @@ describe('Bridge Zora Energy Destination', () => {
bridgeZoraEnergyDestination0x1edd564e as unknown as Transaction,
);
expect(isBridgeZoraEnergyDestination3).toBe(true);

const isBridgeZoraEnergyDestination4 = detect(
bridgeZoraEnergyDestination0xf178e44b as unknown as Transaction,
);
expect(isBridgeZoraEnergyDestination4).toBe(true);
});

it('Should generate context', () => {
Expand All @@ -41,5 +47,14 @@ describe('Bridge Zora Energy Destination', () => {
'0xc761b876e04afa1a67c76bfd8c2c7aa5a5e8e35f COMPLETED_A_CROSS_CHAIN_INTERACTION via 0xf70da97812cb96acdf810712aa562db8dfa3dbef and 0.26754098684670663 ETH was transferred',
);
expect(containsBigInt(transaction2.context)).toBe(false);

const transaction3 = generate(
bridgeZoraEnergyDestination0xf178e44b as unknown as Transaction,
);
expect(transaction3.context?.summaries?.en.title).toBe('Bridge');
expect(contextSummary(transaction3.context)).toBe(
'0x74b78e98093f5b522a7ebdac3b994641ca7c2b20 COMPLETED_A_CROSS_CHAIN_INTERACTION via 0xf70da97812cb96acdf810712aa562db8dfa3dbef and 19692312680620439907443 0x4ed4e862860bed51a9570b96d89af5e1b0efefed was transferred',
);
expect(containsBigInt(transaction3.context)).toBe(false);
});
});
34 changes: 13 additions & 21 deletions src/contextualizers/bridges/reservoir/destination.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {
Transaction,
AssetType,
ETHAsset,
BridgeContextActionEnum,
ContextSummaryVariableType,
ContextETHType,
ContextERC20Type,
ContextERC721Type,
ContextERC1155Type,
Asset,
AssetTransfer,
} from '../../../types';
import { BRIDGE_ZORA_ENERGY } from './constants';

Expand All @@ -26,16 +25,11 @@ export function detect(transaction: Transaction): boolean {
return false;
}

const assetReceived =
transaction.netAssetTransfers &&
transaction.netAssetTransfers[transaction.to] &&
transaction.netAssetTransfers[transaction.to].received
? transaction.netAssetTransfers[transaction.to].received
: [];
const assetTransfer: ETHAsset | undefined = assetReceived.find(
(asset) => asset.type === AssetType.ETH,
) as ETHAsset;
if (!assetTransfer) {
const assetSent =
transaction.assetTransfers?.filter(
(asset) => asset.from === transaction.from,
) ?? [];
if (!assetSent.length) {
return false;
}

Expand All @@ -45,16 +39,14 @@ export function detect(transaction: Transaction): boolean {
export function generate(transaction: Transaction): Transaction {
if (!transaction.to) return transaction;

const assetReceived =
transaction.netAssetTransfers &&
transaction.netAssetTransfers[transaction.to] &&
transaction.netAssetTransfers[transaction.to].received
? transaction.netAssetTransfers[transaction.to].received
: [];
if (!assetReceived?.length) {
const assetSent =
transaction.assetTransfers?.filter(
(asset) => asset.from === transaction.from,
) ?? [];
if (!assetSent?.length) {
return transaction;
}
const assetTransfer: Asset = assetReceived[0];
const assetTransfer: AssetTransfer = assetSent[0];
let asset: ContextSummaryVariableType;
switch (assetTransfer.type) {
case AssetType.ETH:
Expand Down Expand Up @@ -100,7 +92,7 @@ export function generate(transaction: Transaction): Transaction {
variables: {
person: {
type: 'address',
value: transaction.to,
value: assetTransfer.to,
},
address: {
type: 'address',
Expand Down
Loading
Loading