Skip to content

Commit

Permalink
fix: transaction chainId
Browse files Browse the repository at this point in the history
  • Loading branch information
ponyjackal committed Apr 8, 2024
1 parent d65fee6 commit 10bb0a6
Show file tree
Hide file tree
Showing 23 changed files with 32 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/contextualizers/bridges/opStack/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function generate(transaction: Transaction): Transaction {
switch (assetTransfer.type) {
case AssetType.ETH:
asset = {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: assetTransfer.value,
unit: 'wei',
} as ContextETHType;
Expand Down
2 changes: 1 addition & 1 deletion src/contextualizers/bridges/opStack/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function generate(transaction: Transaction): Transaction {
switch (assetTransfer.type) {
case AssetType.ETH:
asset = {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: assetTransfer.value,
unit: 'wei',
} as ContextETHType;
Expand Down
2 changes: 1 addition & 1 deletion src/contextualizers/bridges/reservoir/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function generate(transaction: Transaction): Transaction {
value: 'BRIDGED',
},
asset: {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: assetTransfer.value,
unit: 'wei',
},
Expand Down
2 changes: 1 addition & 1 deletion src/contextualizers/heuristics/erc1155Mint/erc1155Mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function generate(transaction: Transaction): Transaction {
},
minted: { type: 'contextAction', value: 'MINTED' },
price: {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: price,
unit: 'wei',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function generate(transaction: Transaction): Transaction {
}
: ethPayments.length > 0
? {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: totalETHPayment.toString(),
unit: 'wei',
}
Expand Down
2 changes: 1 addition & 1 deletion src/contextualizers/heuristics/erc1155Sale/erc1155Sale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function generate(transaction: Transaction): Transaction {
}
: ethPayments.length > 0
? {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: totalETHPayment.toString(),
unit: 'wei',
}
Expand Down
2 changes: 1 addition & 1 deletion src/contextualizers/heuristics/erc20Mint/erc20Mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function generate(transaction: Transaction): Transaction {
value: recipient,
},
price: {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: price,
unit: 'wei',
},
Expand Down
2 changes: 1 addition & 1 deletion src/contextualizers/heuristics/erc721Mint/erc721Mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function generate(transaction: Transaction): Transaction {
value: sender,
},
price: {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: price,
unit: 'wei',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export function generate(transaction: Transaction): Transaction {
}
: ethPayments.length > 0
? {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: totalETHPayment.toString(),
unit: 'wei',
}
Expand Down
2 changes: 1 addition & 1 deletion src/contextualizers/heuristics/erc721Sale/erc721Sale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function generate(transaction: Transaction): Transaction {
}
: ethPayments.length > 0
? {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: totalETHPayment.toString(),
unit: 'wei',
}
Expand Down
4 changes: 1 addition & 3 deletions src/contextualizers/heuristics/ethTransfer/ethTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export function generate(transaction: Transaction): Transaction {
return transaction;
}

const chainId = transaction.chainId ?? 1;

transaction.context = {
variables: {
sender: {
Expand All @@ -37,7 +35,7 @@ export function generate(transaction: Transaction): Transaction {
},

amount: {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: transaction.value.toString(),
unit: 'wei',
},
Expand Down
2 changes: 1 addition & 1 deletion src/contextualizers/protocol/basepaint/basepaint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const generate = (transaction: Transaction): Transaction => {
value: transaction.from,
},
amount: {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value,
unit: 'wei',
},
Expand Down
13 changes: 6 additions & 7 deletions src/contextualizers/protocol/cryptopunks/cryptopunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const generate = (transaction: Transaction): Transaction => {
) {
return transaction;
}
const chainId = transaction.chainId ?? 1;

const decoded = decodeTransactionInput(
transaction.input as Hex,
Expand Down Expand Up @@ -132,7 +131,7 @@ export const generate = (transaction: Transaction): Transaction => {
tokenId: decoded.args[0].toString(),
};
const price: ContextSummaryVariableType = {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: decoded.args[1].toString(),
unit: 'wei',
};
Expand Down Expand Up @@ -192,7 +191,7 @@ export const generate = (transaction: Transaction): Transaction => {
if (!ethAssetTransfer) return transaction;

const price: ContextSummaryVariableType = {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: ethAssetTransfer.value,
unit: 'wei',
};
Expand Down Expand Up @@ -248,7 +247,7 @@ export const generate = (transaction: Transaction): Transaction => {
tokenId: decoded.args[0].toString(),
};
const price: ContextSummaryVariableType = {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: transaction.value.toString(),
unit: 'wei',
};
Expand Down Expand Up @@ -301,7 +300,7 @@ export const generate = (transaction: Transaction): Transaction => {
const ethAssetTransfer = transaction
.assetTransfers?.[0] as ETHAssetTransfer;
const amount: ContextSummaryVariableType = {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: ethAssetTransfer.value,
unit: 'wei',
};
Expand Down Expand Up @@ -355,7 +354,7 @@ export const generate = (transaction: Transaction): Transaction => {
tokenId: decoded.args[0].toString(),
};
const price: ContextSummaryVariableType = {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: transaction.value.toString(),
unit: 'wei',
};
Expand Down Expand Up @@ -530,7 +529,7 @@ export const generate = (transaction: Transaction): Transaction => {
tokenId: decoded.args[0].toString(),
};
const price: ContextSummaryVariableType = {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: decoded.args[1].toString(),
unit: 'wei',
};
Expand Down
2 changes: 1 addition & 1 deletion src/contextualizers/protocol/disperse/disperse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const generate = (transaction: Transaction): Transaction => {
value: tipTransfer.to,
},
numOfEth: {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: tipTransfer.value,
unit: 'wei',
},
Expand Down
3 changes: 1 addition & 2 deletions src/contextualizers/protocol/farcaster/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ export const generate = (transaction: Transaction): Transaction => {
case 'register': {
const owner = decoded.args[0].to;
const callerIsOwner = owner.toLowerCase() === caller.toLowerCase();
const chainId = transaction.chainId ?? 1;
// Capture cost to register
const cost: ContextSummaryVariableType = {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: transaction.value.toString(),
unit: 'wei',
};
Expand Down
7 changes: 3 additions & 4 deletions src/contextualizers/protocol/friendTech/friendTech.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const contextualize = (transaction: Transaction): Transaction => {

// Contextualize for txs
export const generate = (transaction: Transaction): Transaction => {
const chainId = transaction.chainId ?? 1;
// Failed transaction
if (!transaction.receipt?.status) {
// buyShares(address sharesSubject, uint256 amount)
Expand All @@ -33,7 +32,7 @@ export const generate = (transaction: Transaction): Transaction => {
transaction.context = {
variables: {
price: {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: transaction.value.toString(),
unit: 'wei',
},
Expand Down Expand Up @@ -114,7 +113,7 @@ export const generate = (transaction: Transaction): Transaction => {
transaction.context = {
variables: {
price: {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: ethAmount,
unit: 'wei',
},
Expand Down Expand Up @@ -174,7 +173,7 @@ export const generate = (transaction: Transaction): Transaction => {
transaction.context = {
variables: {
price: {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: ethAmount,
unit: 'wei',
},
Expand Down
5 changes: 2 additions & 3 deletions src/contextualizers/protocol/leeroy/leeroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export const detect = (transaction: Transaction): boolean => {

// Contextualize for mined txs
export const generate = (transaction: Transaction): Transaction => {
const chainId = transaction.chainId ?? 1;
switch (transaction.sigHash) {
case '0x8ee93cf3': {
// post(string)
Expand Down Expand Up @@ -214,7 +213,7 @@ export const generate = (transaction: Transaction): Transaction => {
value: transaction.from,
};
const tipAmount: ContextSummaryVariableType = {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: transaction.value.toString(),
unit: 'wei',
};
Expand All @@ -232,7 +231,7 @@ export const generate = (transaction: Transaction): Transaction => {
const asset = transaction.netAssetTransfers[transaction.to]
.received[0] as ETHAsset;
const leeroyTake: ContextSummaryVariableType = {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: asset.value,
unit: 'wei',
};
Expand Down
3 changes: 1 addition & 2 deletions src/contextualizers/protocol/nouns/auctionHouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export const generate = (transaction: Transaction): Transaction => {
);
if (!decoded) return transaction;

const chainId = transaction.chainId ?? 1;
switch (decoded.functionName) {
case 'createBid': {
transaction.context = {
Expand All @@ -74,7 +73,7 @@ export const generate = (transaction: Transaction): Transaction => {
tokenId: decoded.args[0].toString(),
},
amount: {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: transaction.value.toString(),
unit: 'wei',
},
Expand Down
4 changes: 1 addition & 3 deletions src/contextualizers/protocol/nounsBuilder/auction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export const generate = (transaction: Transaction): Transaction => {
);
if (!decoded) return transaction;

const chainId = transaction.chainId ?? 1;

switch (decoded.functionName) {
case 'createBid': {
const variables: ContextVariable = {
Expand All @@ -81,7 +79,7 @@ export const generate = (transaction: Transaction): Transaction => {
value: decoded.args[0].toString(),
},
amount: {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: transaction.value.toString(),
unit: 'wei',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function generate(transaction: Transaction): Transaction {
value: ethTransfer.to,
},
amount: {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: ethTransfer.value,
unit: 'wei',
},
Expand Down
4 changes: 1 addition & 3 deletions src/contextualizers/protocol/uniswapV2/uniswapV2Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ export const generate = (transaction: Transaction): Transaction => {
);
if (!decoded) return transaction;

const chainId = transaction.chainId ?? 1;

switch (decoded.functionName) {
case 'addLiquidityETH': {
transaction.context = {
Expand All @@ -66,7 +64,7 @@ export const generate = (transaction: Transaction): Transaction => {
value: 'ADDED_LIQUIDITY',
},
numETH: {
type: formatNativeToken(chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: transaction.value.toString(),
unit: 'wei',
},
Expand Down
2 changes: 1 addition & 1 deletion src/contextualizers/protocol/weth/weth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const generate = (transaction: Transaction): Transaction => {
value: transaction.from,
};
const withdrawalAmount: ContextSummaryVariableType = {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: decode.args ? decode.args[0].toString() : '0',
unit: 'wei',
};
Expand Down
4 changes: 2 additions & 2 deletions src/contextualizers/protocol/zoraCreator/zoraCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ export const generate = (transaction: Transaction): Transaction => {
value: sender,
},
price: {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: price,
unit: 'wei',
},
minted: { type: 'contextAction', value: 'MINTED' },
numOfEth: {
type: formatNativeToken(transaction.chainId),
type: formatNativeToken(transaction.chainId ?? 1),
value: decodedLog.args['mintReferralReward'].toString(),
unit: 'wei',
},
Expand Down

0 comments on commit 10bb0a6

Please sign in to comment.