@virtuals-protocol/acp-node 0.1.0-beta.13 → 0.1.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -1
- package/dist/index.d.mts +99 -90
- package/dist/index.d.ts +99 -90
- package/dist/index.js +152 -92
- package/dist/index.mjs +160 -93
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -19,6 +19,9 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
}
|
|
20
20
|
return a;
|
|
21
21
|
};
|
|
22
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
23
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
24
|
+
};
|
|
22
25
|
var __export = (target, all) => {
|
|
23
26
|
for (var name in all)
|
|
24
27
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -61,6 +64,41 @@ var __async = (__this, __arguments, generator) => {
|
|
|
61
64
|
});
|
|
62
65
|
};
|
|
63
66
|
|
|
67
|
+
// package.json
|
|
68
|
+
var require_package = __commonJS({
|
|
69
|
+
"package.json"(exports2, module2) {
|
|
70
|
+
module2.exports = {
|
|
71
|
+
name: "@virtuals-protocol/acp-node",
|
|
72
|
+
version: "0.1.0-beta.15",
|
|
73
|
+
main: "./dist/index.js",
|
|
74
|
+
module: "./dist/index.mjs",
|
|
75
|
+
types: "./dist/index.d.ts",
|
|
76
|
+
scripts: {
|
|
77
|
+
test: 'echo "Error: no test specified" && exit 1',
|
|
78
|
+
tsup: "tsup src/index.ts --dts --format cjs,esm --out-dir dist"
|
|
79
|
+
},
|
|
80
|
+
author: "",
|
|
81
|
+
license: "ISC",
|
|
82
|
+
description: "",
|
|
83
|
+
devDependencies: {
|
|
84
|
+
typescript: "^5.8.3"
|
|
85
|
+
},
|
|
86
|
+
dependencies: {
|
|
87
|
+
"@aa-sdk/core": "^4.30.0",
|
|
88
|
+
"@account-kit/infra": "^4.30.0",
|
|
89
|
+
"@account-kit/smart-contracts": "^4.30.0",
|
|
90
|
+
ajv: "^8.17.1",
|
|
91
|
+
"socket.io-client": "^4.8.1",
|
|
92
|
+
tsup: "^8.5.0",
|
|
93
|
+
viem: "^2.28.2"
|
|
94
|
+
},
|
|
95
|
+
files: [
|
|
96
|
+
"dist"
|
|
97
|
+
]
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
64
102
|
// src/index.ts
|
|
65
103
|
var index_exports = {};
|
|
66
104
|
__export(index_exports, {
|
|
@@ -774,18 +812,25 @@ var baseSepoliaAcpConfig = {
|
|
|
774
812
|
contractAddress: "0xD1D196Ac27Fd386dDc04879a86C074aBF3AD9d0f",
|
|
775
813
|
virtualsTokenAddress: "0xbfAB80ccc15DF6fb7185f9498d6039317331846a",
|
|
776
814
|
alchemyRpcUrl: "https://alchemy-proxy.virtuals.io/api/proxy/rpc",
|
|
777
|
-
acpUrl: "https://acpx-staging.virtuals.io"
|
|
815
|
+
acpUrl: "https://acpx-staging.virtuals.io",
|
|
816
|
+
priorityFeeMultiplier: 2,
|
|
817
|
+
maxFeePerGas: 2e7,
|
|
818
|
+
maxPriorityFeePerGas: 21e6
|
|
778
819
|
};
|
|
779
820
|
var baseAcpConfig = {
|
|
780
821
|
chain: import_infra.base,
|
|
781
822
|
contractAddress: "0x6a1FE26D54ab0d3E1e3168f2e0c0cDa5cC0A0A4A",
|
|
782
823
|
virtualsTokenAddress: "0x0b3e328455c4059EEb9e3f84b5543F74E24e7E1b",
|
|
783
824
|
alchemyRpcUrl: "https://alchemy-proxy-prod.virtuals.io/api/proxy/rpc",
|
|
784
|
-
acpUrl: "https://acpx.virtuals.io"
|
|
825
|
+
acpUrl: "https://acpx.virtuals.io",
|
|
826
|
+
priorityFeeMultiplier: 2,
|
|
827
|
+
maxFeePerGas: 2e7,
|
|
828
|
+
maxPriorityFeePerGas: 21e6
|
|
785
829
|
};
|
|
786
830
|
|
|
787
831
|
// src/acpContractClient.ts
|
|
788
832
|
var import_viem = require("viem");
|
|
833
|
+
var import_op_stack = require("viem/op-stack");
|
|
789
834
|
var MemoType = /* @__PURE__ */ ((MemoType2) => {
|
|
790
835
|
MemoType2[MemoType2["MESSAGE"] = 0] = "MESSAGE";
|
|
791
836
|
MemoType2[MemoType2["CONTEXT_URL"] = 1] = "CONTEXT_URL";
|
|
@@ -806,22 +851,30 @@ var AcpJobPhases = /* @__PURE__ */ ((AcpJobPhases2) => {
|
|
|
806
851
|
return AcpJobPhases2;
|
|
807
852
|
})(AcpJobPhases || {});
|
|
808
853
|
var AcpContractClient = class _AcpContractClient {
|
|
809
|
-
constructor(walletPrivateKey, sessionEntityKeyId, agentWalletAddress, config = baseAcpConfig) {
|
|
854
|
+
constructor(walletPrivateKey, sessionEntityKeyId, agentWalletAddress, config = baseAcpConfig, customRpcUrl) {
|
|
810
855
|
this.walletPrivateKey = walletPrivateKey;
|
|
811
856
|
this.sessionEntityKeyId = sessionEntityKeyId;
|
|
812
857
|
this.agentWalletAddress = agentWalletAddress;
|
|
813
858
|
this.config = config;
|
|
859
|
+
this.customRpcUrl = customRpcUrl;
|
|
860
|
+
this.MAX_RETRIES = 3;
|
|
814
861
|
this.chain = config.chain;
|
|
815
862
|
this.contractAddress = config.contractAddress;
|
|
816
863
|
this.virtualsTokenAddress = config.virtualsTokenAddress;
|
|
864
|
+
this.customRpcUrl = customRpcUrl;
|
|
865
|
+
this.customRpcClient = (0, import_viem.createPublicClient)({
|
|
866
|
+
chain: this.chain,
|
|
867
|
+
transport: this.customRpcUrl ? (0, import_viem.http)(this.customRpcUrl) : (0, import_viem.http)()
|
|
868
|
+
}).extend((0, import_op_stack.publicActionsL2)());
|
|
817
869
|
}
|
|
818
|
-
static build(_0, _1, _2) {
|
|
819
|
-
return __async(this, arguments, function* (walletPrivateKey, sessionEntityKeyId, agentWalletAddress, config = baseAcpConfig) {
|
|
870
|
+
static build(_0, _1, _2, _3) {
|
|
871
|
+
return __async(this, arguments, function* (walletPrivateKey, sessionEntityKeyId, agentWalletAddress, customRpcUrl, config = baseAcpConfig) {
|
|
820
872
|
const acpContractClient = new _AcpContractClient(
|
|
821
873
|
walletPrivateKey,
|
|
822
874
|
sessionEntityKeyId,
|
|
823
875
|
agentWalletAddress,
|
|
824
|
-
config
|
|
876
|
+
config,
|
|
877
|
+
customRpcUrl
|
|
825
878
|
);
|
|
826
879
|
yield acpContractClient.init();
|
|
827
880
|
return acpContractClient;
|
|
@@ -854,6 +907,54 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
854
907
|
get walletAddress() {
|
|
855
908
|
return this.sessionKeyClient.account.address;
|
|
856
909
|
}
|
|
910
|
+
calculateGasFees() {
|
|
911
|
+
return __async(this, null, function* () {
|
|
912
|
+
const { maxFeePerGas, maxPriorityFeePerGas } = yield this.customRpcClient.estimateFeesPerGas();
|
|
913
|
+
let finalMaxFeePerGas = maxFeePerGas;
|
|
914
|
+
let priorityFeeMultiplier = Number(this.config.priorityFeeMultiplier) || 2;
|
|
915
|
+
const overrideMaxFeePerGas = this.config.maxFeePerGas || maxFeePerGas;
|
|
916
|
+
const overrideMaxPriorityFeePerGas = this.config.maxPriorityFeePerGas || maxPriorityFeePerGas;
|
|
917
|
+
finalMaxFeePerGas = BigInt(overrideMaxFeePerGas) + BigInt(overrideMaxPriorityFeePerGas) * BigInt(Math.max(0, priorityFeeMultiplier - 1));
|
|
918
|
+
return finalMaxFeePerGas;
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
handleSendUserOperation(_0) {
|
|
922
|
+
return __async(this, arguments, function* (data, contractAddress = this.contractAddress) {
|
|
923
|
+
const payload = {
|
|
924
|
+
uo: {
|
|
925
|
+
target: contractAddress,
|
|
926
|
+
data
|
|
927
|
+
},
|
|
928
|
+
overrides: {}
|
|
929
|
+
};
|
|
930
|
+
let retries = this.MAX_RETRIES;
|
|
931
|
+
let finalError;
|
|
932
|
+
while (retries > 0) {
|
|
933
|
+
try {
|
|
934
|
+
if (this.MAX_RETRIES > retries) {
|
|
935
|
+
const gasFees = yield this.calculateGasFees();
|
|
936
|
+
payload["overrides"] = {
|
|
937
|
+
maxFeePerGas: `0x${gasFees.toString(16)}`
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
const { hash } = yield this.sessionKeyClient.sendUserOperation(payload);
|
|
941
|
+
yield this.sessionKeyClient.waitForUserOperationTransaction({
|
|
942
|
+
hash
|
|
943
|
+
});
|
|
944
|
+
return hash;
|
|
945
|
+
} catch (error) {
|
|
946
|
+
console.debug("Failed to send user operation", error);
|
|
947
|
+
retries -= 1;
|
|
948
|
+
if (retries === 0) {
|
|
949
|
+
finalError = error;
|
|
950
|
+
break;
|
|
951
|
+
}
|
|
952
|
+
yield new Promise((resolve) => setTimeout(resolve, 2e3 * retries));
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
throw new Error(`Failed to send user operation ${finalError}`);
|
|
956
|
+
});
|
|
957
|
+
}
|
|
857
958
|
getJobId(hash) {
|
|
858
959
|
return __async(this, null, function* () {
|
|
859
960
|
const result = yield this.sessionKeyClient.getUserOperationReceipt(hash);
|
|
@@ -881,98 +982,61 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
881
982
|
Math.floor(expireAt.getTime() / 1e3)
|
|
882
983
|
]
|
|
883
984
|
});
|
|
884
|
-
const
|
|
885
|
-
uo: {
|
|
886
|
-
target: this.contractAddress,
|
|
887
|
-
data
|
|
888
|
-
}
|
|
889
|
-
});
|
|
890
|
-
yield this.sessionKeyClient.waitForUserOperationTransaction({
|
|
891
|
-
hash
|
|
892
|
-
});
|
|
985
|
+
const hash = yield this.handleSendUserOperation(data);
|
|
893
986
|
const jobId = yield this.getJobId(hash);
|
|
894
987
|
return { txHash: hash, jobId };
|
|
895
988
|
} catch (error) {
|
|
896
|
-
console.error(error);
|
|
989
|
+
console.error(`Failed to create job ${error}`);
|
|
897
990
|
throw new Error("Failed to create job");
|
|
898
991
|
}
|
|
899
992
|
});
|
|
900
993
|
}
|
|
901
994
|
approveAllowance(priceInWei) {
|
|
902
995
|
return __async(this, null, function* () {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
})
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
}
|
|
917
|
-
return hash;
|
|
996
|
+
try {
|
|
997
|
+
const data = (0, import_viem.encodeFunctionData)({
|
|
998
|
+
abi: import_viem.erc20Abi,
|
|
999
|
+
functionName: "approve",
|
|
1000
|
+
args: [this.contractAddress, priceInWei]
|
|
1001
|
+
});
|
|
1002
|
+
return yield this.handleSendUserOperation(
|
|
1003
|
+
data,
|
|
1004
|
+
this.virtualsTokenAddress
|
|
1005
|
+
);
|
|
1006
|
+
} catch (error) {
|
|
1007
|
+
console.error(`Failed to approve allowance ${error}`);
|
|
1008
|
+
throw new Error("Failed to approve allowance");
|
|
1009
|
+
}
|
|
918
1010
|
});
|
|
919
1011
|
}
|
|
920
1012
|
createMemo(jobId, content, type, isSecured, nextPhase) {
|
|
921
1013
|
return __async(this, null, function* () {
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
target: this.contractAddress,
|
|
933
|
-
data
|
|
934
|
-
}
|
|
935
|
-
});
|
|
936
|
-
yield this.sessionKeyClient.waitForUserOperationTransaction({
|
|
937
|
-
hash
|
|
938
|
-
});
|
|
939
|
-
return hash;
|
|
940
|
-
} catch (error) {
|
|
941
|
-
console.error(`failed to create memo ${jobId} ${content} ${error}`);
|
|
942
|
-
retries -= 1;
|
|
943
|
-
yield new Promise((resolve) => setTimeout(resolve, 2e3 * retries));
|
|
944
|
-
}
|
|
1014
|
+
try {
|
|
1015
|
+
const data = (0, import_viem.encodeFunctionData)({
|
|
1016
|
+
abi: acpAbi_default,
|
|
1017
|
+
functionName: "createMemo",
|
|
1018
|
+
args: [jobId, content, type, isSecured, nextPhase]
|
|
1019
|
+
});
|
|
1020
|
+
return yield this.handleSendUserOperation(data);
|
|
1021
|
+
} catch (error) {
|
|
1022
|
+
console.error(`Failed to create memo ${jobId} ${content} ${error}`);
|
|
1023
|
+
throw new Error("Failed to create memo");
|
|
945
1024
|
}
|
|
946
|
-
throw new Error("Failed to create memo");
|
|
947
1025
|
});
|
|
948
1026
|
}
|
|
949
1027
|
signMemo(memoId, isApproved, reason) {
|
|
950
1028
|
return __async(this, null, function* () {
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
target: this.contractAddress,
|
|
962
|
-
data
|
|
963
|
-
}
|
|
964
|
-
});
|
|
965
|
-
yield this.sessionKeyClient.waitForUserOperationTransaction({
|
|
966
|
-
hash
|
|
967
|
-
});
|
|
968
|
-
return hash;
|
|
969
|
-
} catch (error) {
|
|
970
|
-
console.error(`failed to sign memo ${error}`);
|
|
971
|
-
retries -= 1;
|
|
972
|
-
yield new Promise((resolve) => setTimeout(resolve, 2e3 * retries));
|
|
973
|
-
}
|
|
1029
|
+
try {
|
|
1030
|
+
const data = (0, import_viem.encodeFunctionData)({
|
|
1031
|
+
abi: acpAbi_default,
|
|
1032
|
+
functionName: "signMemo",
|
|
1033
|
+
args: [memoId, isApproved, reason]
|
|
1034
|
+
});
|
|
1035
|
+
return yield this.handleSendUserOperation(data);
|
|
1036
|
+
} catch (error) {
|
|
1037
|
+
console.error(`Failed to sign memo ${error}`);
|
|
1038
|
+
throw new Error("Failed to sign memo");
|
|
974
1039
|
}
|
|
975
|
-
throw new Error("Failed to sign memo");
|
|
976
1040
|
});
|
|
977
1041
|
}
|
|
978
1042
|
setBudget(jobId, budget) {
|
|
@@ -983,18 +1047,9 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
983
1047
|
functionName: "setBudget",
|
|
984
1048
|
args: [jobId, budget]
|
|
985
1049
|
});
|
|
986
|
-
|
|
987
|
-
uo: {
|
|
988
|
-
target: this.contractAddress,
|
|
989
|
-
data
|
|
990
|
-
}
|
|
991
|
-
});
|
|
992
|
-
yield this.sessionKeyClient.waitForUserOperationTransaction({
|
|
993
|
-
hash
|
|
994
|
-
});
|
|
995
|
-
return hash;
|
|
1050
|
+
return yield this.handleSendUserOperation(data);
|
|
996
1051
|
} catch (error) {
|
|
997
|
-
console.error(error);
|
|
1052
|
+
console.error(`Failed to set budget ${error}`);
|
|
998
1053
|
throw new Error("Failed to set budget");
|
|
999
1054
|
}
|
|
1000
1055
|
});
|
|
@@ -1146,6 +1201,7 @@ var AcpJobOffering = class {
|
|
|
1146
1201
|
var acpJobOffering_default = AcpJobOffering;
|
|
1147
1202
|
|
|
1148
1203
|
// src/acpClient.ts
|
|
1204
|
+
var { version } = require_package();
|
|
1149
1205
|
var AcpClient = class {
|
|
1150
1206
|
constructor(options) {
|
|
1151
1207
|
this.acpContractClient = options.acpContractClient;
|
|
@@ -1162,11 +1218,15 @@ var AcpClient = class {
|
|
|
1162
1218
|
init() {
|
|
1163
1219
|
return __async(this, null, function* () {
|
|
1164
1220
|
const socket = (0, import_socket.io)(this.acpUrl, {
|
|
1165
|
-
auth: __spreadValues(
|
|
1221
|
+
auth: __spreadValues({
|
|
1166
1222
|
walletAddress: this.acpContractClient.walletAddress
|
|
1167
|
-
}
|
|
1223
|
+
}, this.onEvaluate !== this.defaultOnEvaluate && {
|
|
1168
1224
|
evaluatorAddress: this.acpContractClient.walletAddress
|
|
1169
1225
|
}),
|
|
1226
|
+
extraHeaders: {
|
|
1227
|
+
"x-sdk-version": version,
|
|
1228
|
+
"x-sdk-language": "node"
|
|
1229
|
+
},
|
|
1170
1230
|
transports: ["websocket"]
|
|
1171
1231
|
});
|
|
1172
1232
|
socket.on("roomJoined" /* ROOM_JOINED */, (_, callback) => {
|