Skip to content

Commit

Permalink
Merge pull request #4 from Once-Upon/feature/updated-logic-and-types
Browse files Browse the repository at this point in the history
Updated logic and types
  • Loading branch information
pcowgill authored Nov 28, 2023
2 parents 010bb04 + 204b791 commit c1afcdf
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@once-upon/evm-context",
"version": "0.0.2",
"version": "0.0.4",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "jest",
"build": "tsc",
"prepublish": "npm run build",
"prepublishOnly": "npm run build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"grab-transaction": "node ./scripts/grab-transaction.js"
Expand Down
26 changes: 25 additions & 1 deletion src/heuristics/erc20Swap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Transaction } from '../types/transaction';
import { ContextSummaryDefaultType, Transaction } from '../types/transaction';

export function erc20SwapContextualizer(transaction: Transaction): Transaction {
const isERC20Swap = detectERC20Swap(transaction);
Expand Down Expand Up @@ -57,6 +57,30 @@ function generateERC20SwapContext(transaction: Transaction): Transaction {

if (sentCount === 1 && receivedCount === 1 && sent[0].type === 'erc20') {
transaction.context.outcomes['default'] = [
{
key: 'Summary',
value: {
desc: '[[swapper]] [[swapped]] [[sentToken]] for [[receivedToken]]',
swapper: {
type: 'address',
value: address,
},
swapped: {
type: 'contextAction',
value: 'Swapped',
},
sentToken: {
token: sent[0].asset,
type: sent[0].type,
value: sent[0].value,
},
receivedToken: {
token: received[0].asset,
type: received[0].type,
value: received[0].value,
},
} as ContextSummaryDefaultType
},
{
key: 'Swapper',
value: {
Expand Down
59 changes: 58 additions & 1 deletion src/types/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,68 @@ export interface NetAssetTransfers {

export type TransactionContextType = {
type?: string;
category?: 'MULTICHAIN' | 'FUNGIBLE_TOKEN' | 'NFT' | 'CATCHALL' | 'IDENTITY' | 'CORE' | 'OTHER' | 'DEV' | 'UNKNOWN';
category?:
| 'MULTICHAIN'
| 'FUNGIBLE_TOKEN'
| 'NFT'
| 'IDENTITY'
| 'CORE'
| 'OTHER'
| 'DEV'
| 'UNKNOWN';
outcomes?: Record<string, ContextOutcomeType[]>;
crossChainTx?: Transaction[];
};

export type ContextAction =
| 'Bought'
| 'Bridged'
| 'Deployed'
| 'Minted'
| 'Swapped'
| 'Wrapped'
| 'Sent'
| 'Received'
| 'Unwrapped'
| 'Registered'
| 'Renewed'
| 'Committed to'
| 'Received airdrop'
| 'Gave access to'
| 'Interacted with'
| 'Sent message';

export type ContextSummaryVariableType =
| string
| {
type: 'emphasis' | 'address' | 'transaction' | 'eth';
value: string;
}
| {
type: 'contextAction';
value: ContextAction;
}
| {
type: 'erc20';
token: string;
value: string;
}
| {
type: 'erc721';
token: string;
tokenId: string;
}
| {
type: 'erc1155';
token: string;
tokenId: string;
value: string;
};
export type ContextSummaryDefaultType = {
desc: string;
[key: string]: ContextSummaryVariableType;
};

export type ContextOutcomeType = {
key: string;
value: Record<string, any>;
Expand Down

0 comments on commit c1afcdf

Please sign in to comment.