Skip to content

Commit

Permalink
kakarot: invoke returndata and multicall encoding (#531)
Browse files Browse the repository at this point in the history
- Fixes the encoding of multicalls (removes unwanted `0x` hex prefixes)
- Closes #530 by
changing the return type for kakarot's wallet_InvokeTransaction route
  • Loading branch information
fracek authored Nov 1, 2024
2 parents ebfab0d + 23f109e commit 45a0c5a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: kakarot invokeTransaction returndata type & multicall evm encoding",
"packageName": "@starknet-react/kakarot",
"email": "msaug@protonmail.com",
"dependentChangeType": "patch"
}
12 changes: 8 additions & 4 deletions packages/kakarot/src/kakarot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export class KakarotConnector extends Connector {
case "wallet_addInvokeTransaction": {
if (!params) throw new Error("Params are missing");
const { calls } = params as AddInvokeTransactionParameters;
return await provider.request({
const transaction_hash = await provider.request({
method: "eth_sendTransaction",
params: [
{
Expand All @@ -402,6 +402,9 @@ export class KakarotConnector extends Connector {
},
],
});
return {
transaction_hash: transaction_hash,
};
}
case "wallet_signTypedData": {
if (!params) throw new Error("Params are missing");
Expand Down Expand Up @@ -575,7 +578,7 @@ export class KakarotConnector extends Connector {
*/
const prepareTransactionData = (calls: RequestCall[]) => {
const encodedCalls = calls.map((call) => {
return encodeAbiParameters(
const encoded = encodeAbiParameters(
[
{ type: "uint256", name: "contractAddress" },
{ type: "uint256", name: "selector" },
Expand All @@ -587,9 +590,10 @@ const prepareTransactionData = (calls: RequestCall[]) => {
(call.calldata as string[]).map((data: string) => BigInt(data)),
],
);
return encoded.slice(2); // Remove the '0x' prefix from each encoded call
});

const concatenatedCalls = encodedCalls.join("");
const callCount = toHex(calls.length, { size: 32 });
return `${callCount}${concatenatedCalls.slice(2)}` as `0x${string}`;
const callCount = toHex(calls.length, { size: 32 }).slice(2); // Remove the '0x' prefix from the call count
return `0x${callCount}${concatenatedCalls}` as `0x${string}`;
};

0 comments on commit 45a0c5a

Please sign in to comment.