Cow Shed SDK
The Cow Shed SDK is a TypeScript library that provides a set of functions to interact with the Cow Shed contract.
In essence, CoW Shed acts as a user owned smart contract (1/1 multisig if you will) that can execute multiple calls on behalf of the user (once the user has pre-authorized the calls).
Usage
import { ethers } from 'ethers'
import { CowShedSdk, ICoWShedCall, SupportedChainId } from '@cowprotocol/cow-shed'
import { EthersV6Adapter } from '@cowprotocol/sdk-ethers-v6-adapter'
import { JsonRpcProvider, Wallet } from 'ethers'
const provider = new JsonRpcProvider('YOUR_RPC_URL')
const wallet = new Wallet('YOUR_PRIVATE_KEY', provider)
const adapter = new EthersV6Adapter({ provider, signer: wallet })
const cowShedSdk = new CowShedSdk(adapter)
const cowShedAccount = cowShedSdk.getCowShedAccount(1, '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')
const calls: ICoWShedCall[] = [
{
target: '<contract-address-1>',
callData: 'call-data-1',
value: 0n,
isDelegateCall: true,
allowFailure: false,
},
{
target: '<contract-address-2>',
callData: '<call-data-2>',
value: 0n,
isDelegateCall: true,
allowFailure: false,
},
]
const preAuthorizedCall = await cowShedSdk.signCalls({
chainId: SupportedChainId.MAINNET,
calls,
signer: '<privateKeyOrEthersSigner>',
})
const { signedMulticall, gasLimit } = preAuthorizedCall
const { to, data, value } = signedMulticall
let anotherWallet = new ethers.Wallet('<another-private-key>')
const tx = await anotherWallet.sendTransaction({
to,
data,
value,
gasLimit,
})
Using via Cow SDK
You can also import CowShedSdk directly from the main SDK:
import { ethers } from 'ethers'
import { CowShedSdk, ICoWShedCall, SupportedChainId } from '@cowprotocol/cow-sdk'
import { EthersV6Adapter } from '@cowprotocol/sdk-ethers-v6-adapter'
import { JsonRpcProvider, Wallet } from 'ethers'
const provider = new JsonRpcProvider('YOUR_RPC_URL')
const wallet = new Wallet('YOUR_PRIVATE_KEY', provider)
const adapter = new EthersV6Adapter({ provider, signer: wallet })
const cowShedSdk = new CowShedSdk(adapter)