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

Mention the amount of assets that moved #365

Merged
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
34 changes: 32 additions & 2 deletions src/contextualizers/bridges/reservoir/source.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { containsBigInt, contextSummary } from '../../../helpers/utils';
import bridgeZoraEnergySource0x72084c64 from '../../test/transactions/bridgeZoraEnergySource-0x72084c64.json';
import zoraSource0xf2e656b3 from '../../test/transactions/zoraSource-0xf2e656b3.json';
import hopSource0x8603ffab from '../../test/transactions/hop-source-0x8603ffab.json';
import reservoirSource0x35c5ac27 from '../../test/transactions/reservoirSource-0x35c5ac27.json';
import reservoirSource0x7e8671f6 from '../../test/transactions/reservoirSource-0x7e8671f6.json';

describe('Bridge Zora Energy Source', () => {
it('Should detect transaction', () => {
Expand All @@ -21,6 +23,16 @@ describe('Bridge Zora Energy Source', () => {
zoraSource0xf2e656b3 as unknown as Transaction,
);
expect(isBridgeZoraEnergySource3).toBe(true);

const isBridgeZoraEnergySource4 = detect(
reservoirSource0x35c5ac27 as unknown as Transaction,
);
expect(isBridgeZoraEnergySource4).toBe(true);

const isBridgeZoraEnergySource5 = detect(
reservoirSource0x7e8671f6 as unknown as Transaction,
);
expect(isBridgeZoraEnergySource5).toBe(true);
});

it('Should generate context', () => {
Expand All @@ -29,7 +41,7 @@ describe('Bridge Zora Energy Source', () => {
);
expect(transaction1.context?.summaries?.en.title).toBe('Bridge');
expect(contextSummary(transaction1.context)).toBe(
'0x74b78e98093f5b522a7ebdac3b994641ca7c2b20 INITIATED_A_CROSS_CHAIN_INTERACTION via 0xf70da97812cb96acdf810712aa562db8dfa3dbef',
'0x74b78e98093f5b522a7ebdac3b994641ca7c2b20 INITIATED_A_CROSS_CHAIN_INTERACTION via 0xf70da97812cb96acdf810712aa562db8dfa3dbef and 0.020210725986515996 ETH was transferred',
);
expect(containsBigInt(transaction1.context)).toBe(false);

Expand All @@ -38,8 +50,26 @@ describe('Bridge Zora Energy Source', () => {
);
expect(transaction2.context?.summaries?.en.title).toBe('Bridge');
expect(contextSummary(transaction2.context)).toBe(
'0x17cd072cbd45031efc21da538c783e0ed3b25dcc INITIATED_A_CROSS_CHAIN_INTERACTION via 0xf70da97812cb96acdf810712aa562db8dfa3dbef',
'0x17cd072cbd45031efc21da538c783e0ed3b25dcc INITIATED_A_CROSS_CHAIN_INTERACTION via 0xf70da97812cb96acdf810712aa562db8dfa3dbef and 3.829842894866116 ETH was transferred',
);
expect(containsBigInt(transaction2.context)).toBe(false);

const transaction3 = generate(
reservoirSource0x35c5ac27 as unknown as Transaction,
);
expect(transaction3.context?.summaries?.en.title).toBe('Bridge');
expect(contextSummary(transaction3.context)).toBe(
'0x74b78e98093f5b522a7ebdac3b994641ca7c2b20 INITIATED_A_CROSS_CHAIN_INTERACTION via 0xf70da97812cb96acdf810712aa562db8dfa3dbef and 0.201463549452958 ETH was transferred',
);
expect(containsBigInt(transaction3.context)).toBe(false);

const transaction4 = generate(
reservoirSource0x7e8671f6 as unknown as Transaction,
);
expect(transaction4.context?.summaries?.en.title).toBe('Bridge');
expect(contextSummary(transaction4.context)).toBe(
'0x74b78e98093f5b522a7ebdac3b994641ca7c2b20 INITIATED_A_CROSS_CHAIN_INTERACTION via 0xf70da97812cb96acdf810712aa562db8dfa3dbef and 1.2529691246238144 ETH was transferred',
);
expect(containsBigInt(transaction4.context)).toBe(false);
});
});
11 changes: 9 additions & 2 deletions src/contextualizers/bridges/reservoir/source.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { addAssetTransfersToContext } from '../../../helpers/utils';
import {
Transaction,
AssetType,
Expand Down Expand Up @@ -40,7 +41,12 @@ export function detect(transaction: Transaction): boolean {
}

export function generate(transaction: Transaction): Transaction {
if (!transaction.to) return transaction;
if (
!transaction.to ||
!transaction.netAssetTransfers ||
!transaction.assetTransfers
)
return transaction;
const assetSent =
transaction.netAssetTransfers &&
transaction.netAssetTransfers[transaction.from] &&
Expand Down Expand Up @@ -78,5 +84,6 @@ export function generate(transaction: Transaction): Transaction {
},
};

return transaction;
// add asset transfers in context
return addAssetTransfersToContext(transaction);
}
153 changes: 153 additions & 0 deletions src/contextualizers/test/transactions/reservoirSource-0x35c5ac27.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"_id": "661d88fd7b1e9b828ff43784",
"accessList": [],
"blockHash": "0x73a89565bfd97d226f0c54cbfca34d80d76cfbfa7eb42d1d5ffcfd17548e415e",
"blockNumber": 13211140,
"chainId": 8453,
"from": "0x74b78e98093f5b522a7ebdac3b994641ca7c2b20",
"gas": 21064,
"gasPrice": "107763251",
"hash": "0x35c5679b1a4a22903106ee4b58025f2cc7daa7da6206518c44fc5e0b6415ac27",
"input": "0x561c66",
"maxFeePerGas": "116417659",
"maxPriorityFeePerGas": "623587",
"nonce": 196,
"r": "0x59e7bc1dbc9986fc3dcf268cd84c25a5336a2f1e1c4e3c783ed4309db7e07efe",
"s": "0x498076fa2d278b1339c1947a58e2c7e4f598a30cdccb0fa8d1cae45ed1376bf1",
"to": "0xf70da97812cb96acdf810712aa562db8dfa3dbef",
"transactionIndex": 28,
"type": 2,
"v": "0x1",
"value": "201463549452958000",
"yParity": "0x1",
"receipt": {
"blockHash": "0x73a89565bfd97d226f0c54cbfca34d80d76cfbfa7eb42d1d5ffcfd17548e415e",
"blockNumber": 13211140,
"contractAddress": null,
"cumulativeGasUsed": 2996028,
"effectiveGasPrice": 107763251,
"from": "0x74b78e98093f5b522a7ebdac3b994641ca7c2b20",
"gasUsed": 21048,
"l1Fee": "0x758212f80",
"l1GasPrice": "0x36ad2edea",
"l1GasUsed": "0x7a0",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": true,
"to": "0xf70da97812cb96acdf810712aa562db8dfa3dbef",
"transactionHash": "0x35c5679b1a4a22903106ee4b58025f2cc7daa7da6206518c44fc5e0b6415ac27",
"transactionIndex": 28,
"type": "0x2",
"logs": []
},
"decoded": null,
"assetTransfers": [
{
"from": "0x74b78e98093f5b522a7ebdac3b994641ca7c2b20",
"to": "0xf70da97812cb96acdf810712aa562db8dfa3dbef",
"type": "eth",
"value": "201463549452958000"
}
],
"delegateCalls": [],
"neighbor": {
"address": "0x74b78e98093f5b522a7ebdac3b994641ca7c2b20",
"neighbor": "0xf70da97812cb96acdf810712aa562db8dfa3dbef"
},
"errors": [],
"parties": [
"0x74b78e98093f5b522a7ebdac3b994641ca7c2b20",
"0xf70da97812cb96acdf810712aa562db8dfa3dbef"
],
"sigHash": "0x561c66",
"internalSigHashes": [
{
"from": "0x74b78e98093f5b522a7ebdac3b994641ca7c2b20",
"to": "0xf70da97812cb96acdf810712aa562db8dfa3dbef",
"sigHash": "0x561c66"
}
],
"timestamp": 1713211627,
"baseFeePerGas": 107139664,
"transactionFee": "2268200907048",
"logs": [],
"netAssetTransfers": {
"0x74b78e98093f5b522a7ebdac3b994641ca7c2b20": {
"received": [],
"sent": [
{
"type": "eth",
"value": "201463549452958000"
}
]
},
"0xf70da97812cb96acdf810712aa562db8dfa3dbef": {
"received": [
{
"type": "eth",
"value": "201463549452958000"
}
],
"sent": []
}
},
"pseudotransactions": [],
"contractsCreated": [],
"enrichedParties": {
"0x74b78e98093f5b522a7ebdac3b994641ca7c2b20": [
{
"chainId": 0,
"isContract": false,
"ensNew": {
"handle": "ctrlc.eth",
"avatar": "https://assets.airstack.xyz/image/nft/nNBFvZ6wvuIHqDzTFi5pM/pM0Q1IAUgJRNTJrw7f4s3oWqZMygqYPige1il4UPpW34pQtNKENbfJ7IqEfg6CL5BBxAd9CiJ5prXNbNTGXr3FGNoboIm7rAeQtlf9Up5spJtTM022Ew9n/bu+BAmY8Tc74x12eKKldXZgsusflC4=/medium.svg"
},
"bns": {
"handle": null,
"avatar": null
},
"farcaster": {
"handle": "jomessin",
"avatar": "https://lh3.googleusercontent.com/ZsCN-JhNV16yzSYZX7jz_v7kfT85pKT-D7mvgc1KZnLCviPS7GRV9NrS6ezhaaumix2gVKgZ5p5Jkfi7Y3VVQ0sSoJzlztUDAy3hhw",
"fid": 315
}
},
{
"chainId": 8453,
"isContract": false,
"bns": {
"handle": "jomessin.base",
"avatar": "files.basename.app/avatars/0xaecb3897dd378fc3f95c05f85b9eb6680f043fcb7b4873248941d90051b753c6.svg"
},
"ensNew": {
"handle": null,
"avatar": null
},
"farcaster": {
"handle": "jomessin",
"avatar": "https://lh3.googleusercontent.com/ZsCN-JhNV16yzSYZX7jz_v7kfT85pKT-D7mvgc1KZnLCviPS7GRV9NrS6ezhaaumix2gVKgZ5p5Jkfi7Y3VVQ0sSoJzlztUDAy3hhw",
"fid": 315
}
}
],
"0xf70da97812cb96acdf810712aa562db8dfa3dbef": [
{
"chainId": 0,
"isContract": false,
"ensNew": {
"handle": null,
"avatar": null
},
"bns": {
"handle": null,
"avatar": null
},
"farcaster": {
"handle": null,
"avatar": null,
"fid": null
}
}
]
},
"assetsEnriched": {}
}
153 changes: 153 additions & 0 deletions src/contextualizers/test/transactions/reservoirSource-0x7e8671f6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"_id": "6612a4496e33cc5c506b45c3",
"accessList": [],
"blockHash": "0x0b8b17778685e0c9a56a9284617e41a698ae2bac4e01db340326b8c59609ffa4",
"blockNumber": 12854192,
"chainId": 8453,
"from": "0x74b78e98093f5b522a7ebdac3b994641ca7c2b20",
"gas": 21213,
"gasPrice": "39387674",
"hash": "0x7e865637171bc9c7831e60c81985ae31b4c896ecbc7808932c32e83900ba71f6",
"input": "0x41f217",
"maxFeePerGas": "42834653",
"maxPriorityFeePerGas": "4464131",
"nonce": 186,
"r": "0xcfe9598e39312b44ff1a557c2fe0843c2ba97a7b71caa4d3b93a4445c0375ad1",
"s": "0x646ed1a636f93c2b068e629ecf3fc2b0cfdc06d1b5a5e1c48ef7111c71deb7cf",
"to": "0xf70da97812cb96acdf810712aa562db8dfa3dbef",
"transactionIndex": 15,
"type": 2,
"v": "0x1",
"value": "1252969124623814400",
"yParity": "0x1",
"receipt": {
"blockHash": "0x0b8b17778685e0c9a56a9284617e41a698ae2bac4e01db340326b8c59609ffa4",
"blockNumber": 12854192,
"contractAddress": null,
"cumulativeGasUsed": 2020851,
"effectiveGasPrice": 39387674,
"from": "0x74b78e98093f5b522a7ebdac3b994641ca7c2b20",
"gasUsed": 21048,
"l1Fee": "0x91b95c665",
"l1GasPrice": "0x44398c148",
"l1GasUsed": "0x794",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": true,
"to": "0xf70da97812cb96acdf810712aa562db8dfa3dbef",
"transactionHash": "0x7e865637171bc9c7831e60c81985ae31b4c896ecbc7808932c32e83900ba71f6",
"transactionIndex": 15,
"type": "0x2",
"logs": []
},
"decoded": null,
"assetTransfers": [
{
"from": "0x74b78e98093f5b522a7ebdac3b994641ca7c2b20",
"to": "0xf70da97812cb96acdf810712aa562db8dfa3dbef",
"type": "eth",
"value": "1252969124623814400"
}
],
"delegateCalls": [],
"neighbor": {
"address": "0x74b78e98093f5b522a7ebdac3b994641ca7c2b20",
"neighbor": "0xf70da97812cb96acdf810712aa562db8dfa3dbef"
},
"errors": [],
"parties": [
"0x74b78e98093f5b522a7ebdac3b994641ca7c2b20",
"0xf70da97812cb96acdf810712aa562db8dfa3dbef"
],
"sigHash": "0x41f217",
"internalSigHashes": [
{
"from": "0x74b78e98093f5b522a7ebdac3b994641ca7c2b20",
"to": "0xf70da97812cb96acdf810712aa562db8dfa3dbef",
"sigHash": "0x41f217"
}
],
"timestamp": 1712497731,
"baseFeePerGas": 34923543,
"transactionFee": "829031762352",
"logs": [],
"netAssetTransfers": {
"0x74b78e98093f5b522a7ebdac3b994641ca7c2b20": {
"received": [],
"sent": [
{
"type": "eth",
"value": "1252969124623814400"
}
]
},
"0xf70da97812cb96acdf810712aa562db8dfa3dbef": {
"received": [
{
"type": "eth",
"value": "1252969124623814400"
}
],
"sent": []
}
},
"pseudotransactions": [],
"contractsCreated": [],
"enrichedParties": {
"0x74b78e98093f5b522a7ebdac3b994641ca7c2b20": [
{
"chainId": 0,
"isContract": false,
"ensNew": {
"handle": "ctrlc.eth",
"avatar": "https://assets.airstack.xyz/image/nft/nNBFvZ6wvuIHqDzTFi5pM/pM0Q1IAUgJRNTJrw7f4s3oWqZMygqYPige1il4UPpW34pQtNKENbfJ7IqEfg6CL5BBxAd9CiJ5prXNbNTGXr3FGNoboIm7rAeQtlf9Up5spJtTM022Ew9n/bu+BAmY8Tc74x12eKKldXZgsusflC4=/medium.svg"
},
"bns": {
"handle": null,
"avatar": null
},
"farcaster": {
"handle": "jomessin",
"avatar": "https://lh3.googleusercontent.com/ZsCN-JhNV16yzSYZX7jz_v7kfT85pKT-D7mvgc1KZnLCviPS7GRV9NrS6ezhaaumix2gVKgZ5p5Jkfi7Y3VVQ0sSoJzlztUDAy3hhw",
"fid": 315
}
},
{
"chainId": 8453,
"isContract": false,
"bns": {
"handle": "jomessin.base",
"avatar": "files.basename.app/avatars/0xaecb3897dd378fc3f95c05f85b9eb6680f043fcb7b4873248941d90051b753c6.svg"
},
"ensNew": {
"handle": null,
"avatar": null
},
"farcaster": {
"handle": "jomessin",
"avatar": "https://lh3.googleusercontent.com/ZsCN-JhNV16yzSYZX7jz_v7kfT85pKT-D7mvgc1KZnLCviPS7GRV9NrS6ezhaaumix2gVKgZ5p5Jkfi7Y3VVQ0sSoJzlztUDAy3hhw",
"fid": 315
}
}
],
"0xf70da97812cb96acdf810712aa562db8dfa3dbef": [
{
"chainId": 0,
"isContract": false,
"ensNew": {
"handle": null,
"avatar": null
},
"bns": {
"handle": null,
"avatar": null
},
"farcaster": {
"handle": null,
"avatar": null,
"fid": null
}
}
]
},
"assetsEnriched": {}
}
Loading
Loading