Skip to content

Commit 03b6c1d

Browse files
feat: builder code config (#192)
* feat: builder code config * fix: package.json
1 parent 77da4ae commit 03b6c1d

4 files changed

Lines changed: 74 additions & 12 deletions

File tree

package-lock.json

Lines changed: 38 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"ajv": "^8.17.1",
3636
"axios": "^1.13.2",
3737
"jwt-decode": "^4.0.0",
38+
"ox": "^0.13.1",
3839
"socket.io-client": "^4.8.1",
3940
"tsup": "^8.5.0",
4041
"viem": "^2.28.2"

src/contractClients/acpContractClientV2.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import {
3030
import { AcpX402 } from "../acpX402";
3131
import { base, baseSepolia } from "viem/chains";
3232
import MEMO_MANAGER_ABI from "../abis/memoManagerAbi";
33+
import { Attribution } from "ox/erc8021";
34+
import { appendBuilderCodeData } from "../utils";
3335

3436
class AcpContractClientV2 extends BaseAcpContractClient {
3537
private RETRY_CONFIG = {
@@ -47,7 +49,8 @@ class AcpContractClientV2 extends BaseAcpContractClient {
4749
private memoManagerAddress: Address,
4850
private accountManagerAddress: Address,
4951
agentWalletAddress: Address,
50-
config: AcpContractConfig = baseAcpConfigV2
52+
config: AcpContractConfig = baseAcpConfigV2,
53+
private builderCode?: string
5154
) {
5255
super(agentWalletAddress, config);
5356
}
@@ -56,7 +59,8 @@ class AcpContractClientV2 extends BaseAcpContractClient {
5659
walletPrivateKey: Address,
5760
sessionEntityKeyId: number,
5861
agentWalletAddress: Address,
59-
config: AcpContractConfig = baseAcpConfigV2
62+
config: AcpContractConfig = baseAcpConfigV2,
63+
builderCode?: string
6064
) {
6165
const publicClients: Record<
6266
number,
@@ -106,7 +110,8 @@ class AcpContractClientV2 extends BaseAcpContractClient {
106110
memoManagerAddress.result as Address,
107111
accountManagerAddress.result as Address,
108112
agentWalletAddress,
109-
config
113+
config,
114+
builderCode
110115
);
111116

112117
acpContractClient.publicClients = publicClients;
@@ -221,10 +226,16 @@ class AcpContractClientV2 extends BaseAcpContractClient {
221226
throw new AcpError("Session key client not initialized");
222227
}
223228

229+
const dataSuffix = this.builderCode
230+
? Attribution.toDataSuffix({ codes: [this.builderCode] })
231+
: undefined;
232+
224233
const basePayload: any = {
225234
uo: operations.map((operation) => ({
226235
target: operation.contractAddress,
227-
data: operation.data,
236+
data: dataSuffix
237+
? appendBuilderCodeData(operation.data, dataSuffix as Hex)
238+
: operation.data,
228239
value: operation.value,
229240
})),
230241
};

src/utils.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { Address, decodeAbiParameters, encodeAbiParameters } from "viem";
1+
import {
2+
Address,
3+
concatHex,
4+
decodeAbiParameters,
5+
encodeAbiParameters,
6+
Hex,
7+
pad,
8+
} from "viem";
29
import {
310
arbitrum,
411
arbitrumSepolia,
@@ -118,3 +125,15 @@ export function encodeTransferEventMetadata(
118125

119126
return result;
120127
}
128+
129+
export function appendBuilderCodeData(data: Hex, suffix: Hex): Hex {
130+
const opDataByteLength = (data.length - 2) / 2;
131+
const suffixByteLength = (suffix.length - 2) / 2;
132+
const opDataPaddedSize = Math.ceil(opDataByteLength / 32) * 32;
133+
const suffixPaddedSize = Math.ceil(suffixByteLength / 32) * 32;
134+
135+
const paddedData = pad(data, { size: opDataPaddedSize, dir: "right" });
136+
const paddedSuffix = pad(suffix, { size: suffixPaddedSize });
137+
138+
return concatHex([paddedData, paddedSuffix]);
139+
}

0 commit comments

Comments
 (0)