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

Initial proof of concept for a Foundation bid #101

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1,669 changes: 1,669 additions & 0 deletions src/protocol/foundation/abis/OriginalMarket.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/protocol/foundation/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import OriginalMarket from './abis/OriginalMarket.json';

export const FOUNDATION_ORIGINAL_MARKET =
'0xcda72070e455bb31c7690a170224ce43623d0b6f'; // Original Market;

export const ABIs = {
OriginalMarket,
};
25 changes: 25 additions & 0 deletions src/protocol/foundation/foundation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Transaction } from '../../types';
import { contextSummary } from '../../helpers/utils';
import { detect, generate } from './foundation';
import foundationPlaceBidV20x86c62822 from '../../test/transactions/foundation-place-bid-v2-0x86c62822.json';
import catchall0xc35c01ac from '../../test/transactions/catchall-0xc35c01ac.json';

describe('Foundation', () => {
it('Should detect Foundation transaction', () => {
const foundation1 = detect(foundationPlaceBidV20x86c62822 as Transaction);
expect(foundation1).toBe(true);
});

it('Should generate Foundation context', () => {
const foundation1 = generate(foundationPlaceBidV20x86c62822 as Transaction);
const desc1 = contextSummary(foundation1.context);
expect(desc1).toBe(
'0x5d7dcb9f59d4e1cf96463a72e866966149df1552 PLACED_BID on auction 224399',
);
});

it('Should not detect as Foundation', () => {
const leeroy1 = detect(catchall0xc35c01ac as Transaction);
expect(leeroy1).toBe(false);
});
});
90 changes: 90 additions & 0 deletions src/protocol/foundation/foundation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { Interface } from 'ethers/lib/utils';
import { Transaction } from '../../types';
import { decodeTransactionInput } from '../../helpers/utils';
import { FOUNDATION_ORIGINAL_MARKET, ABIs } from './constants';

export const contextualize = (transaction: Transaction): Transaction => {
const isFoundation = detect(transaction);
if (!isFoundation) return transaction;

return generate(transaction);
};

export const detect = (transaction: Transaction): boolean => {
if (!transaction.value) {
return false;
}

if (transaction.to !== FOUNDATION_ORIGINAL_MARKET) {
return false;
}

try {
const iface = new Interface(ABIs.OriginalMarket);
const decoded = iface.parseTransaction({
data: transaction.input,
value: transaction.value,
});

return ['placeBidV2'].includes(decoded.name);
} catch (_) {
return false;
}
};

// Contextualize for mined txs
export const generate = (transaction: Transaction): Transaction => {
const decoded = decodeTransactionInput(
transaction.input,
ABIs.OriginalMarket,
);

switch (decoded.name) {
case 'placeBidV2': {
// Capture auction ID
let auctionID = '';
if (transaction.receipt?.status) {
const originalMarketLog = transaction.logs?.find((log) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Switch to this style #94 (comment)

return log.address === FOUNDATION_ORIGINAL_MARKET;
});
if (originalMarketLog) {
try {
const iface = new Interface(ABIs.OriginalMarket);
const decoded = iface.parseLog({
topics: originalMarketLog.topics,
data: originalMarketLog.data,
});
auctionID = decoded.args.auctionId.toString();
} catch (e) {
console.error(e);
}
}
}
transaction.context = {
variables: {
contextAction: {
type: 'contextAction',
value: 'PLACED_BID',
},
auctionID: {
type: 'auctionID',
value: auctionID,
},
subject: {
type: 'address',
value: transaction.from,
},
},
summaries: {
category: 'PROTOCOL_1',
en: {
title: 'Foundation',
default: '[[subject]] [[contextAction]] on auction [[auctionID]]',
},
},
};

return transaction;
}
}
};
11 changes: 11 additions & 0 deletions src/protocol/foundation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { contextualize as foundation } from './foundation';
import { makeContextualize } from '../../helpers/utils';

const children = { foundation };

const contextualize = makeContextualize(children);

export const ensContextualizer = {
contextualize,
children,
};
Loading