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

feat: add a prehook example for borrow dai and swap #16

Merged
merged 5 commits into from
May 29, 2024

Conversation

meetmangukiya
Copy link
Collaborator

Uses maker protocol to mint DAI using ETH as collateral on the fly in the prehook before the swap is executed.

Uses maker protocol to mint DAI using ETH as collateral on the fly
in the prehook before the swap is executed.
@meetmangukiya
Copy link
Collaborator Author

output
$ ts-node examples/mintDaiAndSwap.ts
Starting anvil...
anvil started at: http://127.0.0.1:8545
Default signers:
0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 => 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d => 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a => 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6 => 0x90F79bf6EB2c4f870365E785982E1f101E93b906
0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a => 0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65
0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba => 0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc
0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e => 0x976EA74026E726554dB657fA54763abd0C3a0aa9
0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356 => 0x14dC79964da2C08b23698B3D3cc7Ca32193d9955
0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97 => 0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f
0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6 => 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720
ensuring all default signers have 10000.0 ether
Deploying COWShed...
verifying deployed addresses has code...
impersonating ENS ownership for cowhooks.eth
COWShed deployed {
  factory: '0x41219a0a9C0b86ED81933c788a6B63Dfef8f17eE',
  implementation: '0x82A9286dB983093Ff234cefCea1d8fA66382876B',
  proxyInitCode: '0x60a034608e57601f61036e38819003918201601f19168301916001600160401b038311848410176093578084926040948552833981010312608e57604b602060458360a9565b920160a9565b6080527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc556040516102b190816100bd8239608051818181608c015261016f0152f35b600080fd5b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b0382168203608e5756fe60806040526004361015610015575b3661019157005b6000803560e01c908163025b22bc14610038575063f851a4400361000e5761010a565b346101075760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101075773ffffffffffffffffffffffffffffffffffffffff60043581811691828203610103577f00000000000000000000000000000000000000000000000000000000000000001633146000146100fe577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8280a280f35b61023a565b8380fd5b80fd5b346101615760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610161576020610143610166565b73ffffffffffffffffffffffffffffffffffffffff60405191168152f35b600080fd5b3330036100fe577f000000000000000000000000000000000000000000000000000000000000000090565b60ff7f68df44b1011761f481358c0f49a711192727fb02c377d697bcb0ea8ff8393ac0541615806101ec575b1561023a5760046040517ff92ee8a9000000000000000000000000000000000000000000000000000000008152fd5b507fc4d66de8000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000006000351614156101bd565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546000808092368280378136915af43d82803e15610277573d90f35b3d90fdfea2646970667358221220b77cca6660707d7113794a16359ee06bf5bbc0412d7df8288d497669faae9bab64736f6c63430008190033'
}
Computed proxy address for user 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 is 0xc5f4EEF1A75E8bAF0DE28C9e5dd1C3Ed3BB189d8
wrapping 10.0 ether for 0x70997970C51812dc3A010C7d01b50e0d17dc79C8...
user 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 hopes 0xc5f4EEF1A75E8bAF0DE28C9e5dd1C3Ed3BB189d8..
tx succeeded: vat.hope: 0x81c5569b891eab7bf6673f9b8f81345792d5c52388ea1db9024ce8f45f2f2c2f
approving 10000000000000000000(n) 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2(token) tokens of 0x70997970C51812dc3A010C7d01b50e0d17dc79C8(owner) to 0x2F0b23f53734252Bda2277357e97e1517d6B042A(spender)...
tx succeeded: undefined: 0x351fdb4b9bb86063268ecf937f13d788e399c62a2ab2c3c554c4b6a41dbbef8a
hash to sign 0x55d7a45527332ca75d08f3d30a4e22761270f68798a748757bc0c0ceb1e19011
actual signature 0x0209a21fad2bf1f1385b31a12bce6be3687412221887ac2e728e29a8421ab6e1 0x79996877c618dffed312057a086cc53c95303c1822b5f164518fd32f650751d3 28
approving 8000000000000000000000(n) 0x6b175474e89094c44da98b954eedeac495271d0f(token) tokens of 0x70997970C51812dc3A010C7d01b50e0d17dc79C8(owner) to 0xC92E8bdf79f0507f65a392b0ab4667716BFE0110(spender)...
Creating order for user: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 {
  sellToken: '0x6b175474e89094c44da98b954eedeac495271d0f',
  buyToken: '0xdef1ca1fb7fbcdc777520aa7f396b4e015f497ab',
  receiver: '0xc5f4EEF1A75E8bAF0DE28C9e5dd1C3Ed3BB189d8',
  sellAmount: 8000000000000000000000n,
  buyAmount: 100000000000000000000n,
  validTo: 1716917322,
  appData: '',
  feeAmount: 0n,
  kind: 'sell',
  partiallyFillable: true,
  sellTokenBalance: 'erc20',
  buyTokenBalance: 'erc20'
}
Create order tx 0x70e4ac68753f2e94cca21ddb7d79acaeeb552d7b901af29c884b08483ea4f224
Settling order for user: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 {
  sellToken: '0x6b175474e89094c44da98b954eedeac495271d0f',
  buyToken: '0xdef1ca1fb7fbcdc777520aa7f396b4e015f497ab',
  receiver: '0xc5f4EEF1A75E8bAF0DE28C9e5dd1C3Ed3BB189d8',
  sellAmount: 8000000000000000000000n,
  buyAmount: 100000000000000000000n,
  validTo: 1716917322,
  appData: '0x4f58ec40dd72902f8966f3e04b0f598d37c5dfa2f2fa4a5c6c70b03f28cd2b68',
  feeAmount: 0n,
  kind: 'sell',
  partiallyFillable: true,
  sellTokenBalance: 'erc20',
  buyTokenBalance: 'erc20'
}
Settle tx 0x33a07efd0d930044fa4b53639fa7b863bc2139d4f145e7a5783793e09486d559
resolving name 0x70997970c51812dc3a010c7d01b50e0d17dc79c8.cowhooks.eth
resolving name 0x70997970C51812dc3A010C7d01b50e0d17dc79C8.cowhooks.eth
{
  resolvedAddressLowerCase: '0xc5f4EEF1A75E8bAF0DE28C9e5dd1C3Ed3BB189d8',
  resolvedAddressChecksummed: '0xc5f4EEF1A75E8bAF0DE28C9e5dd1C3Ed3BB189d8',
  proxyName: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8.cowhooks.eth',
  proxyAddress: '0xc5f4EEF1A75E8bAF0DE28C9e5dd1C3Ed3BB189d8',
  userAddress: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'
}

examples/common.ts Outdated Show resolved Hide resolved
examples/common.ts Outdated Show resolved Hide resolved
examples/mintDaiAndSwap.ts Outdated Show resolved Hide resolved
examples/mintDaiAndSwap.ts Show resolved Hide resolved
examples/mintDaiAndSwap.ts Outdated Show resolved Hide resolved
@meetmangukiya meetmangukiya requested a review from mfw78 May 29, 2024 08:38
@meetmangukiya meetmangukiya merged commit 853206c into main May 29, 2024
2 checks passed
@meetmangukiya meetmangukiya deleted the example-dai-loan branch May 29, 2024 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants