-
Notifications
You must be signed in to change notification settings - Fork 8
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
pcowgill
wants to merge
1
commit into
main
Choose a base branch
from
feature/foundation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) => { | ||
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; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)