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 batchers + build functions #10

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft

add batchers + build functions #10

wants to merge 13 commits into from

Conversation

noahlitvin
Copy link
Contributor

No description provided.

@noahlitvin noahlitvin mentioned this pull request Jan 11, 2024
Copy link
Contributor

@dbeal-eth dbeal-eth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i speak freely on my thoughts for these changes

perhaps we should be splitting the interface into their own dir in the contracts dir?

please bump viem version to 2.5.0

tbh I prefer the adapters naming to oracles

.eslintrc.js Outdated
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one rule I feel like is practically indespensible is no hanging promises https://github.com/usecannon/cannon/blob/main/.eslintrc.json#L55

package.json Outdated
@@ -5,7 +5,8 @@
"main": "dist/src/index.js",
"scripts": {
"build": "forge build && tsc",
"test": "node ./test/pyth.mjs"
"test": "node ./test/pyth.mjs",
"lint:fix": "eslint . --ext .ts --fix"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non fix command would also be useful here

to: address,
data: viem.encodeFunctionData({
abi: ISmartAccount.abi,
functionName: 'executeBatch',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the biggest problem with this method of determining batcher is that the on-chain status of the contract we are sending the txn from should not be the method by which we determine what is supported/not supported in terms of batching. additionally, these types of calls are going to introduce significant lag and unnecessary on-chain calls as we add more supported wallets.

instead, the way we should determine the batching method should be detected by the wallet that the user/selects/connects to their session. For example, if the user connects "Biconomy" wallet, the frontend can be aware of this and report it to the library. Alternatively, the viem.WalletClient can be checked for functionality (ex. if it responds to the erc4336 calls)

if the wallet is not detected, we can always fallback to attempting to do it with trusted forwarder (which can be configured by the frontend as needed)

src/index.ts Outdated
tx: TransactionRequest | TransactionRequest[]
transactions: TransactionRequest | TransactionRequest[]
): Promise<TransactionRequest[]> {
return await (this.enableERC7412(client, transactions, true) as Promise<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needing to cast to Promise<TransactionRequest[]> here (as you imply in your comment) is not a good idea. something seems wrong with this. investigation required.

src/index.ts Outdated
): Promise<TransactionRequest> {
const multicallCalls: TransactionRequest[] = Array.isArray(tx) ? tx : [tx];
const batcher = this.batchers.find(
async (batch) => await batch.batchable(client, transactions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cant use async in javascript find function.

Instead, use Promise.all and find from that result

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and it should go without saying this is extremely inefficient and slow, especially as more wallets are added. it would be better to detect which wallet the user is using by inspecting the wallet that was chosen by their picker, or testing the RPC methods available

src/index.ts Outdated
}

const signedRequiredData = await adapter.fetchOffchainData(
client,
oracleAddress,
oracleQuery
);
)

const priceUpdateTx = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this var should probably be renamed to somethign like offchainDeliveryTx

src/index.ts Outdated
args: [signedRequiredData]
})
}
multicallCalls.unshift(priceUpdateTx as TransactionRequest)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what casting is needed here? are fields missing? is something possibly null? probably best not to cast here unless its really needed.

@dbeal-eth
Copy link
Contributor

ftr I am going to do some work on this branch

dbeal-eth and others added 8 commits February 6, 2024 22:03
this first build focuses on getting really good read function support.

this is accomplished a few ways:

* have a few simple functions which allow for doing the most basic operations
in
* havk a higher level function `callWithOffchainData` which can be used to instantly
add erc7412 to any `call` effective read request
* include a viem extension which can allow for any public provider to be automatically
augmented to be erc7412 read compatible
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.

3 participants