Skip to content

Commit

Permalink
Merge pull request #355 from Once-Upon/feature/ou-2186-for-cross-chai…
Browse files Browse the repository at this point in the history
…n-interactions-other-than-reservoir-if-eth-or

For cross chain interactions other than reservoir if eth or
  • Loading branch information
pcowgill authored Apr 30, 2024
2 parents d48c780 + 8ac806c commit 4e5d329
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/contextualizers/bridges/degen/destination.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Degen Bridge Destination', () => {
);
expect(transaction.context?.summaries?.en.title).toBe('Bridge');
expect(contextSummary(transaction.context)).toBe(
'0x888f05d02ea7b42f32f103c089c1750170830642 COMPLETED_A_CROSS_CHAIN_INTERACTION via 0x729170d38dd5449604f35f349fdfcc9ad08257cd and 470.99999367238779 ETH was transferred',
'0x888f05d02ea7b42f32f103c089c1750170830642 BRIDGED via 0x729170d38dd5449604f35f349fdfcc9ad08257cd and 470.99999367238779 ETH was transferred',
);
expect(containsBigInt(transaction.context)).toBe(false);
});
Expand Down
42 changes: 17 additions & 25 deletions src/contextualizers/bridges/degen/destination.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {
Transaction,
AssetType,
ETHAsset,
BridgeContextActionEnum,
ContextERC1155Type,
ContextERC721Type,
ContextERC20Type,
ContextETHType,
ContextSummaryVariableType,
Asset,
HeuristicContextActionEnum,
AssetTransfer,
} from '../../../types';
import { DEGEN_BRIDGES } from './constants';

Expand All @@ -30,35 +29,28 @@ 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;
}

return true;
}

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 @@ -98,7 +90,7 @@ export function generate(transaction: Transaction): Transaction {
en: {
title: `Bridge`,
default:
'[[person]][[completedACrossChainInteraction]]via[[address]]and[[asset]]was transferred',
'[[person]][[bridged]]via[[address]]and[[asset]]was transferred',
},
},
variables: {
Expand All @@ -111,9 +103,9 @@ export function generate(transaction: Transaction): Transaction {
value: transaction.to,
},
asset,
completedACrossChainInteraction: {
bridged: {
type: 'contextAction',
value: BridgeContextActionEnum.COMPLETED_A_CROSS_CHAIN_INTERACTION,
value: HeuristicContextActionEnum.BRIDGED,
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/contextualizers/bridges/degen/source.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Degen Bridge Source', () => {
);
expect(transaction1.context?.summaries?.en.title).toBe('Bridge');
expect(contextSummary(transaction1.context)).toBe(
'0x729170d38dd5449604f35f349fdfcc9ad08257cd INITIATED_A_CROSS_CHAIN_INTERACTION via 0x43019f8be1f192587883b67dea2994999f5a2de2',
'0x729170d38dd5449604f35f349fdfcc9ad08257cd BRIDGED via 0x43019f8be1f192587883b67dea2994999f5a2de2 and 0.00016 ETH was transferred',
);
expect(containsBigInt(transaction1.context)).toBe(false);
});
Expand Down
77 changes: 54 additions & 23 deletions src/contextualizers/bridges/degen/source.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import {
Transaction,
AssetType,
ETHAsset,
BridgeContextActionEnum,
HeuristicContextActionEnum,
ContextERC721Type,
ContextERC1155Type,
ContextERC20Type,
ContextETHType,
AssetTransfer,
ContextSummaryVariableType,
} from '../../../types';
import { DEGEN_BRIDGES } from './constants';

Expand All @@ -28,15 +33,10 @@ export function detect(transaction: Transaction): boolean {
return false;

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

Expand All @@ -46,24 +46,54 @@ export function detect(transaction: Transaction): boolean {
export function generate(transaction: Transaction): Transaction {
if (!transaction.to) return transaction;
const assetSent =
transaction.netAssetTransfers &&
transaction.netAssetTransfers[transaction.from] &&
transaction.netAssetTransfers[transaction.from].sent
? transaction.netAssetTransfers[transaction.from].sent
: [];
const assetTransfer: ETHAsset | undefined = assetSent.find(
(asset) => asset.type === AssetType.ETH,
) as ETHAsset;
if (!assetTransfer) {
transaction.assetTransfers?.filter(
(asset) => asset.from === transaction.from,
) ?? [];
if (!assetSent?.length) {
return transaction;
}

const assetTransfer: AssetTransfer = assetSent[0];
let asset: ContextSummaryVariableType;
switch (assetTransfer.type) {
case AssetType.ETH:
asset = {
type: AssetType.ETH,
value: assetTransfer.value,
unit: 'wei',
} as ContextETHType;
break;
case AssetType.ERC20:
asset = {
type: AssetType.ERC20,
token: assetTransfer.contract,
value: assetTransfer.value,
} as ContextERC20Type;
break;
case AssetType.ERC721:
asset = {
type: AssetType.ERC721,
token: assetTransfer.contract,
tokenId: assetTransfer.tokenId,
} as ContextERC721Type;
break;
case AssetType.ERC1155:
asset = {
type: AssetType.ERC1155,
token: assetTransfer.contract,
tokenId: assetTransfer.tokenId,
value: assetTransfer.value,
} as ContextERC1155Type;
break;
}

transaction.context = {
summaries: {
category: 'MULTICHAIN',
en: {
title: `Bridge`,
default: '[[person]][[initiated]]via[[address]]',
default:
'[[person]][[bridged]]via[[address]]and[[asset]]was transferred',
},
},
variables: {
Expand All @@ -75,9 +105,10 @@ export function generate(transaction: Transaction): Transaction {
type: 'address',
value: transaction.to,
},
initiated: {
asset,
bridged: {
type: 'contextAction',
value: BridgeContextActionEnum.INITIATED_A_CROSS_CHAIN_INTERACTION,
value: HeuristicContextActionEnum.BRIDGED,
},
},
};
Expand Down

0 comments on commit 4e5d329

Please sign in to comment.