-
Notifications
You must be signed in to change notification settings - Fork 48
feat(composable): add JIT poller SDK support #927
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
Open
igorroncevic
wants to merge
4
commits into
main
Choose a base branch
from
feat/composable-cow-poller-sdk
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.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e7101cf
feat(composable): add JIT poller helpers
igorroncevic e640f37
fix(composable): sync final Poller ABI
igorroncevic 90ee3de
fix(composable): sync Poller SDK with CowShed authorization
igorroncevic a40eb99
test(composable): exercise Poller public exports
igorroncevic 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
This file contains hidden or 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
This file contains hidden or 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,43 @@ | ||
| import { getGlobalAdapter } from '@cowprotocol/sdk-common' | ||
|
|
||
| import { ComposableCowPollerAbi } from './abis/ComposableCowPollerAbi' | ||
| import { ComposableCowPollerSchedule, ComposableCowPollerScheduleKey } from './types' | ||
|
|
||
| export { ComposableCowPollerAbi } from './abis/ComposableCowPollerAbi' | ||
|
|
||
| const SCHEDULE_ID_ABI = ['address', 'address', 'address', 'bytes32'] | ||
|
|
||
| /** | ||
| * Calculates the app-data-independent poller schedule ID. | ||
| */ | ||
| export function getScheduleId(schedule: ComposableCowPollerScheduleKey): string { | ||
| const encoded = getGlobalAdapter().utils.encodeAbi(SCHEDULE_ID_ABI, [ | ||
| schedule.funder, | ||
| schedule.handler, | ||
| schedule.owner, | ||
| schedule.salt, | ||
| ]) | ||
|
|
||
| return getGlobalAdapter().utils.keccak256(encoded) | ||
| } | ||
|
|
||
| /** | ||
| * Encodes a transaction that registers a JIT funding schedule. | ||
| */ | ||
| export function encodeRegister(schedule: ComposableCowPollerSchedule): string { | ||
| return getGlobalAdapter().utils.encodeFunction(ComposableCowPollerAbi, 'register', [schedule]) as string | ||
| } | ||
|
|
||
| /** | ||
| * Encodes the app-data pre-hook that pulls funds for one active TWAP part. | ||
| */ | ||
| export function encodePollFunds(id: string): string { | ||
| return getGlobalAdapter().utils.encodeFunction(ComposableCowPollerAbi, 'pollFunds', [id]) as string | ||
| } | ||
|
|
||
| /** | ||
| * Encodes a transaction that disables a JIT funding schedule. | ||
| */ | ||
| export function encodeRevoke(id: string): string { | ||
| return getGlobalAdapter().utils.encodeFunction(ComposableCowPollerAbi, 'revoke', [id]) as string | ||
| } |
This file contains hidden or 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,134 @@ | ||
| export const ComposableCowPollerAbi = [ | ||
| { | ||
| type: 'constructor', | ||
| inputs: [ | ||
| { name: 'composableCow', type: 'address', internalType: 'contract ComposableCoW' }, | ||
| { name: 'cowShedFactory', type: 'address', internalType: 'contract ICowShedFactory' }, | ||
| ], | ||
| stateMutability: 'nonpayable', | ||
| }, | ||
| { | ||
| type: 'function', | ||
| name: 'COMPOSABLE_COW', | ||
| inputs: [], | ||
| outputs: [{ name: '', type: 'address', internalType: 'contract ComposableCoW' }], | ||
| stateMutability: 'view', | ||
| }, | ||
| { | ||
| type: 'function', | ||
| name: 'COW_SHED_FACTORY', | ||
| inputs: [], | ||
| outputs: [{ name: '', type: 'address', internalType: 'contract ICowShedFactory' }], | ||
| stateMutability: 'view', | ||
| }, | ||
| { | ||
| type: 'function', | ||
| name: 'funded', | ||
| inputs: [ | ||
| { name: '', type: 'bytes32', internalType: 'bytes32' }, | ||
| { name: '', type: 'bytes32', internalType: 'bytes32' }, | ||
| ], | ||
| outputs: [{ name: '', type: 'bool', internalType: 'bool' }], | ||
| stateMutability: 'view', | ||
| }, | ||
| { | ||
| type: 'function', | ||
| name: 'pollFunds', | ||
| inputs: [{ name: 'id', type: 'bytes32', internalType: 'bytes32' }], | ||
| outputs: [], | ||
| stateMutability: 'nonpayable', | ||
| }, | ||
| { | ||
| type: 'function', | ||
| name: 'register', | ||
| inputs: [ | ||
| { | ||
| name: 'schedule', | ||
| type: 'tuple', | ||
| internalType: 'struct ComposableCowPoller.Schedule', | ||
| components: [ | ||
| { name: 'handler', type: 'address', internalType: 'contract IConditionalOrderGenerator' }, | ||
| { name: 'funder', type: 'address', internalType: 'address' }, | ||
| { name: 'owner', type: 'address', internalType: 'address' }, | ||
| { name: 'salt', type: 'bytes32', internalType: 'bytes32' }, | ||
| { name: 'staticInput', type: 'bytes', internalType: 'bytes' }, | ||
| ], | ||
| }, | ||
| ], | ||
| outputs: [{ name: 'id', type: 'bytes32', internalType: 'bytes32' }], | ||
| stateMutability: 'nonpayable', | ||
| }, | ||
| { | ||
| type: 'function', | ||
| name: 'revoke', | ||
| inputs: [{ name: 'id', type: 'bytes32', internalType: 'bytes32' }], | ||
| outputs: [], | ||
| stateMutability: 'nonpayable', | ||
| }, | ||
| { | ||
| type: 'function', | ||
| name: 'scheduleId', | ||
| inputs: [ | ||
| { | ||
| name: 'schedule', | ||
| type: 'tuple', | ||
| internalType: 'struct ComposableCowPoller.Schedule', | ||
| components: [ | ||
| { name: 'handler', type: 'address', internalType: 'contract IConditionalOrderGenerator' }, | ||
| { name: 'funder', type: 'address', internalType: 'address' }, | ||
| { name: 'owner', type: 'address', internalType: 'address' }, | ||
| { name: 'salt', type: 'bytes32', internalType: 'bytes32' }, | ||
| { name: 'staticInput', type: 'bytes', internalType: 'bytes' }, | ||
| ], | ||
| }, | ||
| ], | ||
| outputs: [{ name: '', type: 'bytes32', internalType: 'bytes32' }], | ||
| stateMutability: 'pure', | ||
| }, | ||
| { | ||
| type: 'function', | ||
| name: 'schedules', | ||
| inputs: [{ name: '', type: 'bytes32', internalType: 'bytes32' }], | ||
| outputs: [ | ||
| { name: 'handler', type: 'address', internalType: 'contract IConditionalOrderGenerator' }, | ||
| { name: 'funder', type: 'address', internalType: 'address' }, | ||
| { name: 'owner', type: 'address', internalType: 'address' }, | ||
| { name: 'salt', type: 'bytes32', internalType: 'bytes32' }, | ||
| { name: 'staticInput', type: 'bytes', internalType: 'bytes' }, | ||
| ], | ||
| stateMutability: 'view', | ||
| }, | ||
| { | ||
| type: 'event', | ||
| name: 'Pulled', | ||
| inputs: [ | ||
| { name: 'id', type: 'bytes32', indexed: true, internalType: 'bytes32' }, | ||
| { name: 'orderDigest', type: 'bytes32', indexed: false, internalType: 'bytes32' }, | ||
| { name: 'amount', type: 'uint256', indexed: false, internalType: 'uint256' }, | ||
| ], | ||
| anonymous: false, | ||
| }, | ||
| { | ||
| type: 'event', | ||
| name: 'ScheduleRegistered', | ||
| inputs: [ | ||
| { name: 'id', type: 'bytes32', indexed: true, internalType: 'bytes32' }, | ||
| { name: 'owner', type: 'address', indexed: true, internalType: 'address' }, | ||
| { name: 'funder', type: 'address', indexed: true, internalType: 'address' }, | ||
| ], | ||
| anonymous: false, | ||
| }, | ||
| { | ||
| type: 'event', | ||
| name: 'ScheduleRevoked', | ||
| inputs: [ | ||
| { name: 'id', type: 'bytes32', indexed: true, internalType: 'bytes32' }, | ||
| { name: 'owner', type: 'address', indexed: true, internalType: 'address' }, | ||
| { name: 'funder', type: 'address', indexed: true, internalType: 'address' }, | ||
| ], | ||
| anonymous: false, | ||
| }, | ||
| { type: 'error', name: 'NoSchedule', inputs: [] }, | ||
| { type: 'error', name: 'OrderNotLive', inputs: [] }, | ||
| { type: 'error', name: 'UnauthorizedCaller', inputs: [] }, | ||
| ] as const |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,105 @@ | ||
| import { setGlobalAdapter } from '@cowprotocol/sdk-common' | ||
|
|
||
| import { | ||
| ComposableCowPollerAbi, | ||
| type ComposableCowPollerSchedule, | ||
| encodePollFunds, | ||
| encodeRegister, | ||
| encodeRevoke, | ||
| getScheduleId, | ||
| } from '../src' | ||
| import { createAdapters } from './setup' | ||
|
|
||
| const SCHEDULE: ComposableCowPollerSchedule = { | ||
| handler: '0x1111111111111111111111111111111111111111', | ||
| funder: '0x2222222222222222222222222222222222222222', | ||
| owner: '0x3333333333333333333333333333333333333333', | ||
| salt: '0x0000000000000000000000000000000000000000000000000000000000000001', | ||
| staticInput: '0x1234', | ||
| } | ||
|
|
||
| const SCHEDULE_ID = '0x7b1516d117fa5dd96fddfb9489b52af1c3cca64e1bc88c32324bdd6a92c6057c' | ||
| const REGISTER_CALLDATA = | ||
| '0x80313a250000000000000000000000000000000000000000000000000000000000000020000000000000000000000000111111111111111111111111111111111111111100000000000000000000000022222222222222222222222222222222222222220000000000000000000000003333333333333333333333333333333333333333000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000021234000000000000000000000000000000000000000000000000000000000000' | ||
| const POLL_FUNDS_CALLDATA = '0xf83740307b1516d117fa5dd96fddfb9489b52af1c3cca64e1bc88c32324bdd6a92c6057c' | ||
| const REVOKE_CALLDATA = '0xb75c7dc67b1516d117fa5dd96fddfb9489b52af1c3cca64e1bc88c32324bdd6a92c6057c' | ||
|
|
||
| describe('ComposableCowPoller - Multi-Adapter Tests', () => { | ||
| const adapters = createAdapters() | ||
|
|
||
| test('derives the Solidity schedule ID across adapters', () => { | ||
| for (const adapter of Object.values(adapters)) { | ||
| setGlobalAdapter(adapter) | ||
| expect(getScheduleId(SCHEDULE)).toEqual(SCHEDULE_ID) | ||
| } | ||
| }) | ||
|
|
||
| test('does not include staticInput in the schedule ID', () => { | ||
| const updatedStaticInput = { ...SCHEDULE, staticInput: '0xdeadbeef' } | ||
|
|
||
| for (const adapter of Object.values(adapters)) { | ||
| setGlobalAdapter(adapter) | ||
| expect(getScheduleId(updatedStaticInput)).toEqual(SCHEDULE_ID) | ||
| } | ||
| }) | ||
|
|
||
| test('encodes final poller calls across adapters', () => { | ||
| for (const adapter of Object.values(adapters)) { | ||
| setGlobalAdapter(adapter) | ||
| expect(encodeRegister(SCHEDULE)).toEqual(REGISTER_CALLDATA) | ||
| expect(encodePollFunds(SCHEDULE_ID)).toEqual(POLL_FUNDS_CALLDATA) | ||
| expect(encodeRevoke(SCHEDULE_ID)).toEqual(REVOKE_CALLDATA) | ||
| } | ||
| }) | ||
|
|
||
| test('exports the combined poller interface, not the removed topUp method', () => { | ||
| const functionNames = ComposableCowPollerAbi.filter((item) => item.type === 'function') | ||
| .map((item) => item.name) | ||
| .sort() | ||
| const errorNames = ComposableCowPollerAbi.filter((item) => item.type === 'error') | ||
| .map((item) => item.name) | ||
| .sort() | ||
| const eventNames = ComposableCowPollerAbi.filter((item) => item.type === 'event') | ||
| .map((item) => item.name) | ||
| .sort() | ||
| const constructor = ComposableCowPollerAbi.find((item) => item.type === 'constructor') | ||
| const register = ComposableCowPollerAbi.find((item) => item.type === 'function' && item.name === 'register') | ||
| const scheduleId = ComposableCowPollerAbi.find((item) => item.type === 'function' && item.name === 'scheduleId') | ||
| const funded = ComposableCowPollerAbi.find((item) => item.type === 'function' && item.name === 'funded') | ||
| const scheduleRevoked = ComposableCowPollerAbi.find( | ||
| (item) => item.type === 'event' && item.name === 'ScheduleRevoked', | ||
| ) | ||
|
|
||
| expect(functionNames).toEqual([ | ||
| 'COMPOSABLE_COW', | ||
| 'COW_SHED_FACTORY', | ||
| 'funded', | ||
| 'pollFunds', | ||
| 'register', | ||
| 'revoke', | ||
| 'scheduleId', | ||
| 'schedules', | ||
| ]) | ||
| expect(errorNames).toEqual(['NoSchedule', 'OrderNotLive', 'UnauthorizedCaller']) | ||
| expect(eventNames).toEqual(['Pulled', 'ScheduleRegistered', 'ScheduleRevoked']) | ||
| expect(constructor).toEqual({ | ||
| inputs: [ | ||
| { internalType: 'contract ComposableCoW', name: 'composableCow', type: 'address' }, | ||
| { internalType: 'contract ICowShedFactory', name: 'cowShedFactory', type: 'address' }, | ||
| ], | ||
| stateMutability: 'nonpayable', | ||
| type: 'constructor', | ||
| }) | ||
| expect(scheduleId?.inputs).toEqual(register?.inputs) | ||
| expect(funded?.inputs).toEqual([ | ||
| { internalType: 'bytes32', name: '', type: 'bytes32' }, | ||
| { internalType: 'bytes32', name: '', type: 'bytes32' }, | ||
| ]) | ||
| expect(funded?.outputs).toEqual([{ internalType: 'bool', name: '', type: 'bool' }]) | ||
| expect(scheduleRevoked?.inputs).toEqual([ | ||
| { indexed: true, internalType: 'bytes32', name: 'id', type: 'bytes32' }, | ||
| { indexed: true, internalType: 'address', name: 'owner', type: 'address' }, | ||
| { indexed: true, internalType: 'address', name: 'funder', type: 'address' }, | ||
| ]) | ||
| }) | ||
| }) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.