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

🔥 Add readme #9

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2023-present Coinbase

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions README.md
110 changes: 110 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<br/>

<p align="center">
<h1>Bytecode Caller</h1>
</a>
</p>

<p align="center">
Simple yet powerful multicall successor
<p>

<br>

## About

- 💡 **Lightweight** - 0 external dependencies
- 🧹 **Clean use** - create your queries with a smart-contract language of choice
- ⛓️ **Interdependent queries** - get data dependent on other call results in a single call
- 🚀 **No limits** - works on every EVM based chain, on every block in time

## Overview

Bytecode Caller allows you to compose any number of dependant on each other calls using e.g. Solidity. In the following example there is a smart contract *FriendWhoWantsMangoes* and *MangoSeller*. If you want to know the price, first you need to call *askHowManyMangoes* on *FriendWhoWantsMangoes*, and then take the result and call *askForMangoesPrice* on *MangoSeller* with it. Normally, using usual RPC call or calls via Multisig, in this scenario you would need 2 separate calls.

Bytecode Caller allows you to make it in one call. Simply, you will need to write MangoPriceReader smart contract and pass its compiled bytecode to **createDataForBytecode** as in example below.

**Note:** There is no need to deploy the MangoPriceReader.

Contract that you want to read:

```solidity
contract FriendWhoWantsMangoes {
function askHowManyMangoes() external pure returns(uint256) {
return 10;
}
}

contract MangoSeller {
function askForMangoesPrice(uint256 numberOfMangoes) external pure returns(uint256) {
return numberOfMangoes * 20;
}
}
```

Query contract to use: *(No need to deploy this smart contract)*

```solidity
contract MangoPriceReader {
function estimateExpenses(address friend, address seller) public pure returns (uint256) {
uint256 mangoesToBuy = FriendWhoWantsMangoes(friend).askHowManyMangoes();
return MangoSeller(seller).askForMangoesPrice(mangoesToBuy);
}
}
```


### Use with viem

```typescript
import { bytecode } from 'build/MangoPriceReader.sol/MangoPriceReader.json'

const friendContractAddress = '0xE930Eb2004e09f6492F49f58A2F35C0B1382c68C'
const sellerContractAddress = '0x2d5b56ee345698c000061B81755eB5E70eA8DEa1'

const abi = parseAbi(['function estimateExpenses(address, address) external view returns (uint256)'])
const callData = encodeFunctionData({
abi,
functionName: 'read',
args: [friendContractAddress, sellerContractAddress],
})

const byteCodeCallerData = createDataForBytecode(bytecode, callData)
const result = await client.call({
to: null,
data: byteCodeCallerData,
})

const decodedResult = decodeFunctionResult({
abi,
functionName: 'estimateExpenses',
data: result.data!,
})
```

### Use with ethers 6

```typescript
import { bytecode } from 'build/MangoPriceReader.sol/MangoPriceReader.json'

const friendContractAddress = '0xE930Eb2004e09f6492F49f58A2F35C0B1382c68C'
const sellerContractAddress = '0x2d5b56ee345698c000061B81755eB5E70eA8DEa1'

const PriceReaderInterface = new Interface([
'function estimateExpenses(address, address) external view returns (uint256)',
])

const callData = PriceReaderInterface.encodeFunctionData('read', [friendContractAddress, sellerContractAddress])
const bytecodeCallerData = createDataForBytecode(bytecode, callData)

const result = await provider.call({
to: null,
data: bytecodeCallerData,
})

const decodedResult = PriceReaderInterface.decodeFunctionResult('estimateExpenses', result)
```

## License

[MIT](LICENSE.md) License
Loading