Skip to content

Commit

Permalink
Vault interface (#237)
Browse files Browse the repository at this point in the history
- Abstract away vault interactions to its own encapsulating interface
    - Initial, partial, implementation
- Add: Vault abstraction framework to easily work with different onchain vaults
- Add: `eth_defi.velvet` 
- Add: `QuoterV2` support for Uniswap v3 - needed to get Base prices
  • Loading branch information
miohtama authored Nov 23, 2024
1 parent c0d1adb commit b25c58b
Show file tree
Hide file tree
Showing 41 changed files with 2,709 additions and 254 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Current

- Change `launch_anvil()` to use latest hardfork by default instead of `london`

- Add: Vault abstraction framework to easily work with different onchain vaults. Abstract away vault interactions to its own encapsulating interface.
- Add: Support for [Velvet Capital vaults](https://www.velvet.capital/)
- Add: `wait_and_broadcast_multiple_nodes_mev_blocker()` for [MEV Blocker](https://mevblocker.io) - because the tx
broadcast must be sequential
- Add: `fetch_erc20_balances_multicall` read multiple ERC-20 balances using Multicall library
- Add: `QuoterV2` support for Uniswap v3 - needed to get Base prices
- Change `launch_anvil()` to use latest hardfork by default instead of `london`

# 0.26.1

Expand Down
2 changes: 1 addition & 1 deletion contracts/uniswap-v3-periphery
Submodule uniswap-v3-periphery updated 62 files
+25 −0 .github/stale.yml
+ audits/abdk/audit.pdf
+23 −3 contracts/NonfungibleTokenPositionDescriptor.sol
+1 −1 contracts/base/Multicall.sol
+2 −2 contracts/base/PeripheryPayments.sol
+149 −0 contracts/examples/PairFlash.sol
+1 −1 contracts/interfaces/IERC20Metadata.sol
+0 −1 contracts/interfaces/INonfungiblePositionManager.sol
+0 −5 contracts/interfaces/INonfungibleTokenPositionDescriptor.sol
+1 −1 contracts/interfaces/IQuoter.sol
+98 −0 contracts/interfaces/IQuoterV2.sol
+273 −0 contracts/lens/QuoterV2.sol
+39 −0 contracts/lens/UniswapInterfaceMulticall.sol
+1 −1 contracts/libraries/NFTDescriptor.sol
+8 −8 contracts/libraries/NFTSVG.sol
+180 −0 contracts/libraries/OracleLibrary.sol
+8 −0 contracts/libraries/Path.sol
+96 −0 contracts/libraries/PoolTicksCounter.sol
+167 −0 contracts/libraries/PositionValue.sol
+62 −0 contracts/libraries/SqrtPriceMathPartial.sol
+48 −0 contracts/test/MockObservable.sol
+82 −0 contracts/test/MockObservations.sol
+18 −0 contracts/test/NonfungiblePositionManagerPositionsGasTest.sol
+67 −0 contracts/test/OracleTest.sol
+18 −0 contracts/test/PoolTicksCounterTest.sol
+57 −0 contracts/test/PositionValueTest.sol
+25 −0 deploys.md
+25 −2 hardhat.config.ts
+8 −6 package.json
+9 −6 test/CallbackValidation.spec.ts
+6 −1 test/Multicall.spec.ts
+32 −34 test/NFTDescriptor.spec.ts
+51 −18 test/NonfungiblePositionManager.spec.ts
+133 −30 test/NonfungibleTokenPositionDescriptor.spec.ts
+675 −0 test/OracleLibrary.spec.ts
+168 −0 test/PairFlash.spec.ts
+1 −3 test/Path.spec.ts
+1 −3 test/PeripheryImmutableState.spec.ts
+1 −3 test/PoolAddress.spec.ts
+280 −0 test/PoolTicksCounter.spec.ts
+490 −0 test/PositionValue.spec.ts
+12 −40 test/Quoter.spec.ts
+578 −0 test/QuoterV2.spec.ts
+5 −3 test/SelfPermit.spec.ts
+109 −23 test/SwapRouter.gas.spec.ts
+15 −15 test/SwapRouter.spec.ts
+6 −7 test/TickLens.spec.ts
+44 −35 test/V3Migrator.spec.ts
+2 −2 test/__snapshots__/NFTDescriptor.spec.ts.snap
+1 −1 test/__snapshots__/NFTDescriptor.svg
+10 −8 test/__snapshots__/NonfungiblePositionManager.spec.ts.snap
+3 −0 test/__snapshots__/OracleLibrary.spec.ts.snap
+3 −0 test/__snapshots__/PairFlash.spec.ts.snap
+11 −0 test/__snapshots__/PositionValue.spec.ts.snap
+51 −0 test/__snapshots__/QuoterV2.spec.ts.snap
+16 −10 test/__snapshots__/SwapRouter.gas.spec.ts.snap
+1 −1 test/__snapshots__/V3Migrator.spec.ts.snap
+16 −9 test/shared/completeFixture.ts
+5 −0 test/shared/extractJSONFromURI.ts
+153 −0 test/shared/quoter.ts
+2 −103 testnet-deploys.md
+295 −355 yarn.lock
2 changes: 1 addition & 1 deletion contracts/velvet-core
Submodule velvet-core updated 1 files
+15 −9 README.md
19 changes: 0 additions & 19 deletions eth_defi/abi/uniswap_v3/INonfungibleTokenPositionDescriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,6 @@
"contractName": "INonfungibleTokenPositionDescriptor",
"sourceName": "contracts/interfaces/INonfungibleTokenPositionDescriptor.sol",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "token",
"type": "address"
},
{
"indexed": false,
"internalType": "int256",
"name": "priority",
"type": "int256"
}
],
"name": "UpdateTokenRatioPriority",
"type": "event"
},
{
"inputs": [
{
Expand Down
211 changes: 211 additions & 0 deletions eth_defi/abi/uniswap_v3/IQuoterV2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "IQuoterV2",
"sourceName": "contracts/interfaces/IQuoterV2.sol",
"abi": [
{
"inputs": [
{
"internalType": "bytes",
"name": "path",
"type": "bytes"
},
{
"internalType": "uint256",
"name": "amountIn",
"type": "uint256"
}
],
"name": "quoteExactInput",
"outputs": [
{
"internalType": "uint256",
"name": "amountOut",
"type": "uint256"
},
{
"internalType": "uint160[]",
"name": "sqrtPriceX96AfterList",
"type": "uint160[]"
},
{
"internalType": "uint32[]",
"name": "initializedTicksCrossedList",
"type": "uint32[]"
},
{
"internalType": "uint256",
"name": "gasEstimate",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"components": [
{
"internalType": "address",
"name": "tokenIn",
"type": "address"
},
{
"internalType": "address",
"name": "tokenOut",
"type": "address"
},
{
"internalType": "uint256",
"name": "amountIn",
"type": "uint256"
},
{
"internalType": "uint24",
"name": "fee",
"type": "uint24"
},
{
"internalType": "uint160",
"name": "sqrtPriceLimitX96",
"type": "uint160"
}
],
"internalType": "struct IQuoterV2.QuoteExactInputSingleParams",
"name": "params",
"type": "tuple"
}
],
"name": "quoteExactInputSingle",
"outputs": [
{
"internalType": "uint256",
"name": "amountOut",
"type": "uint256"
},
{
"internalType": "uint160",
"name": "sqrtPriceX96After",
"type": "uint160"
},
{
"internalType": "uint32",
"name": "initializedTicksCrossed",
"type": "uint32"
},
{
"internalType": "uint256",
"name": "gasEstimate",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "path",
"type": "bytes"
},
{
"internalType": "uint256",
"name": "amountOut",
"type": "uint256"
}
],
"name": "quoteExactOutput",
"outputs": [
{
"internalType": "uint256",
"name": "amountIn",
"type": "uint256"
},
{
"internalType": "uint160[]",
"name": "sqrtPriceX96AfterList",
"type": "uint160[]"
},
{
"internalType": "uint32[]",
"name": "initializedTicksCrossedList",
"type": "uint32[]"
},
{
"internalType": "uint256",
"name": "gasEstimate",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"components": [
{
"internalType": "address",
"name": "tokenIn",
"type": "address"
},
{
"internalType": "address",
"name": "tokenOut",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "uint24",
"name": "fee",
"type": "uint24"
},
{
"internalType": "uint160",
"name": "sqrtPriceLimitX96",
"type": "uint160"
}
],
"internalType": "struct IQuoterV2.QuoteExactOutputSingleParams",
"name": "params",
"type": "tuple"
}
],
"name": "quoteExactOutputSingle",
"outputs": [
{
"internalType": "uint256",
"name": "amountIn",
"type": "uint256"
},
{
"internalType": "uint160",
"name": "sqrtPriceX96After",
"type": "uint160"
},
{
"internalType": "uint32",
"name": "initializedTicksCrossed",
"type": "uint32"
},
{
"internalType": "uint256",
"name": "gasEstimate",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x",
"deployedBytecode": "0x",
"linkReferences": {},
"deployedLinkReferences": {}
}
56 changes: 56 additions & 0 deletions eth_defi/abi/uniswap_v3/MockObservable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "MockObservable",
"sourceName": "contracts/test/MockObservable.sol",
"abi": [
{
"inputs": [
{
"internalType": "uint32[]",
"name": "secondsAgos",
"type": "uint32[]"
},
{
"internalType": "int56[]",
"name": "tickCumulatives",
"type": "int56[]"
},
{
"internalType": "uint160[]",
"name": "secondsPerLiquidityCumulativeX128s",
"type": "uint160[]"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "uint32[]",
"name": "secondsAgos",
"type": "uint32[]"
}
],
"name": "observe",
"outputs": [
{
"internalType": "int56[]",
"name": "tickCumulatives",
"type": "int56[]"
},
{
"internalType": "uint160[]",
"name": "secondsPerLiquidityCumulativeX128s",
"type": "uint160[]"
}
],
"stateMutability": "view",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b506040516107803803806107808339818101604052606081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825186602082028301116401000000008211171561008557600080fd5b82525081516020918201928201910280838360005b838110156100b257818101518382015260200161009a565b50505050905001604052602001805160405193929190846401000000008211156100db57600080fd5b9083019060208201858111156100f057600080fd5b825186602082028301116401000000008211171561010d57600080fd5b82525081516020918201928201910280838360005b8381101561013a578181015183820152602001610122565b505050509050016040526020018051604051939291908464010000000082111561016357600080fd5b90830190602082018581111561017857600080fd5b825186602082028301116401000000008211171561019557600080fd5b82525081516020918201928201910280838360005b838110156101c25781810151838201526020016101aa565b50505050905001604052505050825160021480156101e1575081516002145b80156101ee575080516002145b61023f576040805162461bcd60e51b815260206004820152601660248201527f496e76616c6964207465737420636173652073697a6500000000000000000000604482015290519081900360640190fd5b60405180606001604052808460008151811061025757fe5b602002602001015163ffffffff1681526020018360008151811061027757fe5b602002602001015160060b81526020018260008151811061029457fe5b6020908102919091018101516001600160a01b03908116909252825160008054928501516040958601519094166b01000000000000000000000002600160581b600160f81b031960069590950b66ffffffffffffff166401000000000266ffffffffffffff60201b1963ffffffff90941663ffffffff1990951694909417929092169290921792909216919091179055805160608101909152835181908590600190811061033e57fe5b602002602001015163ffffffff1681526020018360018151811061035e57fe5b602002602001015160060b81526020018260018151811061037b57fe5b6020908102919091018101516001600160a01b03908116909252825160018054928501516040909501519093166b01000000000000000000000002600160581b600160f81b031960069590950b66ffffffffffffff166401000000000266ffffffffffffff60201b1963ffffffff90931663ffffffff19909416939093179190911691909117929092169190911790555050506103638061041d6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063883bdbfd14610030575b600080fd5b6100a06004803603602081101561004657600080fd5b81019060208101813564010000000081111561006157600080fd5b82018360208201111561007357600080fd5b8035906020019184602083028401116401000000008311171561009557600080fd5b509092509050610139565b604051808060200180602001838103835285818151815260200191508051906020019060200280838360005b838110156100e45781810151838201526020016100cc565b50505050905001838103825284818151815260200191508051906020019060200280838360005b8381101561012357818101518382015260200161010b565b5050505090500194505050505060405180910390f35b60008054606091829163ffffffff1690859085908161015457fe5b9050602002013563ffffffff1663ffffffff1614801561019c57506001805463ffffffff16908590859081811061018757fe5b9050602002013563ffffffff1663ffffffff16145b61020757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f496e76616c696420746573742063617365000000000000000000000000000000604482015290519081900360640190fd5b6040805160028082526060820183526000926020830190803683375050600080548351939450640100000000900460060b9284925061024257fe5b600692830b830b602091820292909201015260018054835164010000000090910490920b91839190811061027257fe5b600692830b90920b602092830291909101820152604080516002808252606082018352600093919290918301908036833750506000805483519394506b010000000000000000000000900473ffffffffffffffffffffffffffffffffffffffff16928492506102dd57fe5b73ffffffffffffffffffffffffffffffffffffffff92831660209182029290920101526001805483516b01000000000000000000000090910490921691839190811061032557fe5b73ffffffffffffffffffffffffffffffffffffffff909216602092830291909101909101529092509050925092905056fea164736f6c6343000706000a",
"deployedBytecode": "0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063883bdbfd14610030575b600080fd5b6100a06004803603602081101561004657600080fd5b81019060208101813564010000000081111561006157600080fd5b82018360208201111561007357600080fd5b8035906020019184602083028401116401000000008311171561009557600080fd5b509092509050610139565b604051808060200180602001838103835285818151815260200191508051906020019060200280838360005b838110156100e45781810151838201526020016100cc565b50505050905001838103825284818151815260200191508051906020019060200280838360005b8381101561012357818101518382015260200161010b565b5050505090500194505050505060405180910390f35b60008054606091829163ffffffff1690859085908161015457fe5b9050602002013563ffffffff1663ffffffff1614801561019c57506001805463ffffffff16908590859081811061018757fe5b9050602002013563ffffffff1663ffffffff16145b61020757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f496e76616c696420746573742063617365000000000000000000000000000000604482015290519081900360640190fd5b6040805160028082526060820183526000926020830190803683375050600080548351939450640100000000900460060b9284925061024257fe5b600692830b830b602091820292909201015260018054835164010000000090910490920b91839190811061027257fe5b600692830b90920b602092830291909101820152604080516002808252606082018352600093919290918301908036833750506000805483519394506b010000000000000000000000900473ffffffffffffffffffffffffffffffffffffffff16928492506102dd57fe5b73ffffffffffffffffffffffffffffffffffffffff92831660209182029290920101526001805483516b01000000000000000000000090910490921691839190811061032557fe5b73ffffffffffffffffffffffffffffffffffffffff909216602092830291909101909101529092509050925092905056fea164736f6c6343000706000a",
"linkReferences": {},
"deployedLinkReferences": {}
}
Loading

0 comments on commit b25c58b

Please sign in to comment.