Skip to content

Commit

Permalink
feat: sdk for CowShed hooks (#219)
Browse files Browse the repository at this point in the history
* add cow shed related abi and move contracts codegen folder to common

* add initial cow shed package

* add tests to the cow-shed module

* add wip comments

* chore(examples): add local cow sdk version to cra example

* feat(examples): add generate cow shed hook calldata

* revert ethers version change

* improve bigint readability

* Add cow-shed module (#2)

* add cow shed related abi and move contracts codegen folder to common

* add initial cow shed package

* add tests to the cow-shed module

* add wip comments

* chore(examples): add local cow sdk version to cra example

* feat(examples): add generate cow shed hook calldata

* revert ethers version change

* improve bigint readability

---------

Co-authored-by: José Ribeiro <[email protected]>

* chore: add contracts deployment

* refactor: change computeProxyAddress method to proxyOf

* refactor: simplify domain of function

* chore: add deployed proxy init code

---------

Co-authored-by: José Ribeiro <[email protected]>
  • Loading branch information
yvesfracari and ribeirojose authored Sep 23, 2024
1 parent b898ea3 commit f07d2d6
Show file tree
Hide file tree
Showing 25 changed files with 1,328 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ jest.results.json
*.iml
.yalc
yalc.lock
src/composable/generated
src/common/generated
docs/typedoc/
139 changes: 139 additions & 0 deletions abi/CoWShed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
[
{ "inputs": [], "name": "AlreadyInitialized", "type": "error" },
{ "inputs": [], "name": "DeadlineElapsed", "type": "error" },
{ "inputs": [], "name": "InvalidSignature", "type": "error" },
{ "inputs": [], "name": "InvalidSignature", "type": "error" },
{ "inputs": [], "name": "NonceAlreadyUsed", "type": "error" },
{ "inputs": [], "name": "OnlyAdmin", "type": "error" },
{ "inputs": [], "name": "OnlyAdminOrTrustedExecutorOrSelf", "type": "error" },
{ "inputs": [], "name": "OnlySelf", "type": "error" },
{ "inputs": [], "name": "OnlyTrustedExecutor", "type": "error" },
{
"anonymous": false,
"inputs": [
{ "indexed": false, "internalType": "bytes32", "name": "r", "type": "bytes32" },
{ "indexed": false, "internalType": "bytes32", "name": "s", "type": "bytes32" },
{ "indexed": false, "internalType": "uint8", "name": "v", "type": "uint8" }
],
"name": "RSV",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": false, "internalType": "address", "name": "previousExecutor", "type": "address" },
{ "indexed": false, "internalType": "address", "name": "newExecutor", "type": "address" }
],
"name": "TrustedExecutorChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": true, "internalType": "address", "name": "implementation", "type": "address" }],
"name": "Upgraded",
"type": "event"
},
{
"inputs": [{ "internalType": "address", "name": "resolver", "type": "address" }],
"name": "claimWithResolver",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "domainSeparator",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"components": [
{ "internalType": "address", "name": "target", "type": "address" },
{ "internalType": "uint256", "name": "value", "type": "uint256" },
{ "internalType": "bytes", "name": "callData", "type": "bytes" },
{ "internalType": "bool", "name": "allowFailure", "type": "bool" },
{ "internalType": "bool", "name": "isDelegateCall", "type": "bool" }
],
"internalType": "struct Call[]",
"name": "calls",
"type": "tuple[]"
},
{ "internalType": "bytes32", "name": "nonce", "type": "bytes32" },
{ "internalType": "uint256", "name": "deadline", "type": "uint256" },
{ "internalType": "bytes", "name": "signature", "type": "bytes" }
],
"name": "executeHooks",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "factory", "type": "address" },
{ "internalType": "bool", "name": "claimResolver", "type": "bool" }
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes32", "name": "nonce", "type": "bytes32" }],
"name": "nonces",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes32", "name": "nonce", "type": "bytes32" }],
"name": "revokeNonce",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"components": [
{ "internalType": "address", "name": "target", "type": "address" },
{ "internalType": "uint256", "name": "value", "type": "uint256" },
{ "internalType": "bytes", "name": "callData", "type": "bytes" },
{ "internalType": "bool", "name": "allowFailure", "type": "bool" },
{ "internalType": "bool", "name": "isDelegateCall", "type": "bool" }
],
"internalType": "struct Call[]",
"name": "calls",
"type": "tuple[]"
}
],
"name": "trustedExecuteHooks",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "trustedExecutor",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "newImplementation", "type": "address" }],
"name": "updateImplementation",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "who", "type": "address" }],
"name": "updateTrustedExecutor",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{ "stateMutability": "payable", "type": "receive" }
]
134 changes: 134 additions & 0 deletions abi/CoWShedFactory.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
[
{
"inputs": [
{ "internalType": "address", "name": "impl", "type": "address" },
{ "internalType": "bytes32", "name": "bName", "type": "bytes32" },
{ "internalType": "bytes32", "name": "bNode", "type": "bytes32" }
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{ "inputs": [], "name": "InvalidSignature", "type": "error" },
{ "inputs": [], "name": "NonceAlreadyUsed", "type": "error" },
{ "inputs": [], "name": "SettingEnsRecordsFailed", "type": "error" },
{
"anonymous": false,
"inputs": [
{ "indexed": false, "internalType": "address", "name": "user", "type": "address" },
{ "indexed": false, "internalType": "address", "name": "shed", "type": "address" }
],
"name": "COWShedBuilt",
"type": "event"
},
{
"inputs": [{ "internalType": "bytes32", "name": "node", "type": "bytes32" }],
"name": "addr",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "baseName",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "baseNode",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"components": [
{ "internalType": "address", "name": "target", "type": "address" },
{ "internalType": "uint256", "name": "value", "type": "uint256" },
{ "internalType": "bytes", "name": "callData", "type": "bytes" },
{ "internalType": "bool", "name": "allowFailure", "type": "bool" },
{ "internalType": "bool", "name": "isDelegateCall", "type": "bool" }
],
"internalType": "struct Call[]",
"name": "calls",
"type": "tuple[]"
},
{ "internalType": "bytes32", "name": "nonce", "type": "bytes32" },
{ "internalType": "uint256", "name": "deadline", "type": "uint256" },
{ "internalType": "address", "name": "user", "type": "address" },
{ "internalType": "bytes", "name": "signature", "type": "bytes" }
],
"name": "executeHooks",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"name": "forwardResolutionNodeToAddress",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "implementation",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "user", "type": "address" }],
"name": "initializeEns",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "user", "type": "address" },
{ "internalType": "bool", "name": "withEns", "type": "bool" }
],
"name": "initializeProxy",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes32", "name": "node", "type": "bytes32" }],
"name": "name",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "ownerOf",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "who", "type": "address" }],
"name": "proxyOf",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"name": "reverseResolutionNodeToAddress",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes4", "name": "interfaceId", "type": "bytes4" }],
"name": "supportsInterface",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "pure",
"type": "function"
}
]
22 changes: 11 additions & 11 deletions examples/cra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@cowprotocol/cow-sdk": "^4.0.3",
"@cowprotocol/cow-sdk": "../../",
"@safe-global/api-kit": "^1.3.0",
"@safe-global/protocol-kit": "^1.2.0",
"@testing-library/jest-dom": "^5.16.5",
Expand Down Expand Up @@ -34,21 +34,21 @@
]
},
"devDependencies": {
"buffer": "npm:[email protected]",
"assert": "npm:[email protected]",
"http": "npm:stream-http@^3.2.0",
"https": "npm:https-browserify@^1.0.0",
"zlib": "npm:browserify-zlib@^0.2.0",
"crypto": "npm:[email protected]",
"stream": "npm:[email protected]",
"url": "npm:[email protected]",
"util": "npm:[email protected]",
"@types/jest": "^29.5.0",
"@types/node": "^18.15.10",
"@types/react": "^18.0.30",
"@types/react-dom": "^18.0.11",
"add": "^2.0.6",
"assert": "npm:[email protected]",
"buffer": "npm:[email protected]",
"crypto": "npm:[email protected]",
"http": "npm:stream-http@^3.2.0",
"https": "npm:https-browserify@^1.0.0",
"stream": "npm:[email protected]",
"typescript": "^5.0.2",
"yarn": "^1.22.19"
"url": "npm:[email protected]",
"util": "npm:[email protected]",
"yarn": "^1.22.19",
"zlib": "npm:browserify-zlib@^0.2.0"
}
}
2 changes: 2 additions & 0 deletions examples/cra/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useWeb3Info } from './hooks/useWeb3Info'
import { ChainIdContext } from './context'
import { QuickStartPage } from './pages/quickStart'
import { SmartContractWallet } from './pages/smartContractWallet'
import { GenerateCowShedHookCallDataPage } from './pages/cowShedHook'

const EXAMPLES: ExampleProps[] = [
{ title: 'Quick start', Component: QuickStartPage },
Expand All @@ -22,6 +23,7 @@ const EXAMPLES: ExampleProps[] = [
{ title: 'Sign order cancellation', Component: SignOrderCancellationPage },
{ title: 'Send order cancellation', Component: SendOrderCancellationPage },
{ title: 'Smart contract wallet', Component: SmartContractWallet },
{ title: 'Generate hook with CoW Shed', Component: GenerateCowShedHookCallDataPage },
]

interface ExampleProps {
Expand Down
Loading

0 comments on commit f07d2d6

Please sign in to comment.