@exagent/agent 0.1.40 → 0.1.41
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/dist/chunk-34JBZQO6.mjs +9475 -0
- package/dist/chunk-AEASQNGT.mjs +9475 -0
- package/dist/cli.js +112 -31
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +53 -53
- package/dist/index.d.ts +53 -53
- package/dist/index.js +112 -31
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2666,13 +2666,6 @@ var VAULT_FACTORY_ABI = [
|
|
|
2666
2666
|
outputs: [{ type: "address" }],
|
|
2667
2667
|
stateMutability: "view"
|
|
2668
2668
|
},
|
|
2669
|
-
{
|
|
2670
|
-
type: "function",
|
|
2671
|
-
name: "canCreateVault",
|
|
2672
|
-
inputs: [{ name: "creator", type: "address" }],
|
|
2673
|
-
outputs: [{ name: "canCreate", type: "bool" }, { name: "reason", type: "string" }],
|
|
2674
|
-
stateMutability: "view"
|
|
2675
|
-
},
|
|
2676
2669
|
{
|
|
2677
2670
|
type: "function",
|
|
2678
2671
|
name: "createVault",
|
|
@@ -2689,10 +2682,17 @@ var VAULT_FACTORY_ABI = [
|
|
|
2689
2682
|
},
|
|
2690
2683
|
{
|
|
2691
2684
|
type: "function",
|
|
2692
|
-
name: "
|
|
2685
|
+
name: "MIN_SEED_AMOUNT",
|
|
2693
2686
|
inputs: [],
|
|
2694
2687
|
outputs: [{ type: "uint256" }],
|
|
2695
2688
|
stateMutability: "view"
|
|
2689
|
+
},
|
|
2690
|
+
{
|
|
2691
|
+
type: "function",
|
|
2692
|
+
name: "allowedAssets",
|
|
2693
|
+
inputs: [{ name: "asset", type: "address" }],
|
|
2694
|
+
outputs: [{ type: "bool" }],
|
|
2695
|
+
stateMutability: "view"
|
|
2696
2696
|
}
|
|
2697
2697
|
];
|
|
2698
2698
|
var VAULT_ABI = [
|
|
@@ -2790,23 +2790,34 @@ var VaultManager = class {
|
|
|
2790
2790
|
} catch {
|
|
2791
2791
|
}
|
|
2792
2792
|
}
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2793
|
+
let canCreate = true;
|
|
2794
|
+
let cannotCreateReason = null;
|
|
2795
|
+
if (hasVault) {
|
|
2796
|
+
canCreate = false;
|
|
2797
|
+
cannotCreateReason = "Vault already exists for this agent";
|
|
2798
|
+
} else {
|
|
2799
|
+
try {
|
|
2800
|
+
const isAssetAllowed = await this.publicClient.readContract({
|
|
2801
|
+
address: this.addresses.vaultFactory,
|
|
2802
|
+
abi: VAULT_FACTORY_ABI,
|
|
2803
|
+
functionName: "allowedAssets",
|
|
2804
|
+
args: [this.addresses.usdc]
|
|
2805
|
+
});
|
|
2806
|
+
if (!isAssetAllowed) {
|
|
2807
|
+
canCreate = false;
|
|
2808
|
+
cannotCreateReason = "USDC is not an allowed asset on the vault factory";
|
|
2809
|
+
}
|
|
2810
|
+
} catch {
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2802
2813
|
return {
|
|
2803
2814
|
hasVault,
|
|
2804
2815
|
vaultAddress,
|
|
2805
2816
|
totalAssets,
|
|
2806
|
-
canCreateVault:
|
|
2807
|
-
cannotCreateReason
|
|
2808
|
-
requirementsMet:
|
|
2809
|
-
requirements
|
|
2817
|
+
canCreateVault: canCreate,
|
|
2818
|
+
cannotCreateReason,
|
|
2819
|
+
requirementsMet: canCreate,
|
|
2820
|
+
requirements: { isBypassed: true }
|
|
2810
2821
|
};
|
|
2811
2822
|
}
|
|
2812
2823
|
/**
|
|
@@ -2854,11 +2865,67 @@ var VaultManager = class {
|
|
|
2854
2865
|
if (existingVault) {
|
|
2855
2866
|
return { success: false, error: "Vault already exists", vaultAddress: existingVault };
|
|
2856
2867
|
}
|
|
2857
|
-
const status = await this.getVaultStatus();
|
|
2858
|
-
if (!status.canCreateVault) {
|
|
2859
|
-
return { success: false, error: status.cannotCreateReason || "Requirements not met" };
|
|
2860
|
-
}
|
|
2861
2868
|
const seed = seedAmount || BigInt(1e8);
|
|
2869
|
+
let usdcBalance;
|
|
2870
|
+
try {
|
|
2871
|
+
usdcBalance = await this.publicClient.readContract({
|
|
2872
|
+
address: this.addresses.usdc,
|
|
2873
|
+
abi: import_viem3.erc20Abi,
|
|
2874
|
+
functionName: "balanceOf",
|
|
2875
|
+
args: [this.account.address]
|
|
2876
|
+
});
|
|
2877
|
+
} catch {
|
|
2878
|
+
return { success: false, error: "Failed to read USDC balance" };
|
|
2879
|
+
}
|
|
2880
|
+
if (usdcBalance < seed) {
|
|
2881
|
+
const needed = Number(seed) / 1e6;
|
|
2882
|
+
const have = Number(usdcBalance) / 1e6;
|
|
2883
|
+
return {
|
|
2884
|
+
success: false,
|
|
2885
|
+
error: `Insufficient USDC: need ${needed} USDC seed but wallet has ${have} USDC. Fund ${this.account.address} with at least ${needed} USDC and retry.`
|
|
2886
|
+
};
|
|
2887
|
+
}
|
|
2888
|
+
try {
|
|
2889
|
+
const isAllowed = await this.publicClient.readContract({
|
|
2890
|
+
address: this.addresses.vaultFactory,
|
|
2891
|
+
abi: VAULT_FACTORY_ABI,
|
|
2892
|
+
functionName: "allowedAssets",
|
|
2893
|
+
args: [this.addresses.usdc]
|
|
2894
|
+
});
|
|
2895
|
+
if (!isAllowed) {
|
|
2896
|
+
return { success: false, error: "USDC is not whitelisted on the vault factory. Contact protocol admin." };
|
|
2897
|
+
}
|
|
2898
|
+
} catch {
|
|
2899
|
+
}
|
|
2900
|
+
try {
|
|
2901
|
+
const currentAllowance = await this.publicClient.readContract({
|
|
2902
|
+
address: this.addresses.usdc,
|
|
2903
|
+
abi: import_viem3.erc20Abi,
|
|
2904
|
+
functionName: "allowance",
|
|
2905
|
+
args: [this.account.address, this.addresses.vaultFactory]
|
|
2906
|
+
});
|
|
2907
|
+
if (currentAllowance < seed) {
|
|
2908
|
+
console.log(`Approving ${Number(seed) / 1e6} USDC to VaultFactory...`);
|
|
2909
|
+
const approveHash = await this.walletClient.writeContract({
|
|
2910
|
+
address: this.addresses.usdc,
|
|
2911
|
+
abi: import_viem3.erc20Abi,
|
|
2912
|
+
functionName: "approve",
|
|
2913
|
+
args: [this.addresses.vaultFactory, seed],
|
|
2914
|
+
chain: import_chains2.base,
|
|
2915
|
+
account: this.account
|
|
2916
|
+
});
|
|
2917
|
+
const approveReceipt = await this.publicClient.waitForTransactionReceipt({ hash: approveHash });
|
|
2918
|
+
if (approveReceipt.status !== "success") {
|
|
2919
|
+
return { success: false, error: "USDC approval transaction failed" };
|
|
2920
|
+
}
|
|
2921
|
+
console.log("USDC approved successfully");
|
|
2922
|
+
}
|
|
2923
|
+
} catch (error) {
|
|
2924
|
+
return {
|
|
2925
|
+
success: false,
|
|
2926
|
+
error: `USDC approval failed: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2927
|
+
};
|
|
2928
|
+
}
|
|
2862
2929
|
const vaultName = this.config.vaultConfig.defaultName || `${this.config.agentName} Trading Vault`;
|
|
2863
2930
|
const vaultSymbol = this.config.vaultConfig.defaultSymbol || `ex${this.config.agentName.replace(/[^a-zA-Z]/g, "").slice(0, 4).toUpperCase()}`;
|
|
2864
2931
|
const feeRecipient = this.config.vaultConfig.feeRecipient || this.account.address;
|
|
@@ -2880,8 +2947,9 @@ var VaultManager = class {
|
|
|
2880
2947
|
});
|
|
2881
2948
|
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
2882
2949
|
if (receipt.status !== "success") {
|
|
2883
|
-
return { success: false, error: "
|
|
2950
|
+
return { success: false, error: "createVault transaction reverted on-chain", txHash: hash };
|
|
2884
2951
|
}
|
|
2952
|
+
this.lastVaultCheck = 0;
|
|
2885
2953
|
const vaultAddress = await this.getVaultAddress();
|
|
2886
2954
|
this.cachedVaultAddress = vaultAddress;
|
|
2887
2955
|
return {
|
|
@@ -2890,10 +2958,23 @@ var VaultManager = class {
|
|
|
2890
2958
|
txHash: hash
|
|
2891
2959
|
};
|
|
2892
2960
|
} catch (error) {
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
}
|
|
2961
|
+
const msg = error instanceof Error ? error.message : "Unknown error";
|
|
2962
|
+
if (msg.includes("NotAgentOwner")) {
|
|
2963
|
+
return { success: false, error: "This wallet is not the owner of the agent. Only the agent owner can create a fund." };
|
|
2964
|
+
}
|
|
2965
|
+
if (msg.includes("InsufficientStake")) {
|
|
2966
|
+
return { success: false, error: "Staking requirement not met. This should not happen with StakingStub \u2014 contact protocol admin." };
|
|
2967
|
+
}
|
|
2968
|
+
if (msg.includes("FrontierCannotCreateVault")) {
|
|
2969
|
+
return { success: false, error: "Frontier-risk agents cannot create funds. Change the agent risk universe first." };
|
|
2970
|
+
}
|
|
2971
|
+
if (msg.includes("VaultAlreadyExists")) {
|
|
2972
|
+
return { success: false, error: "A fund already exists for this agent and asset." };
|
|
2973
|
+
}
|
|
2974
|
+
if (msg.includes("InsufficientSeed")) {
|
|
2975
|
+
return { success: false, error: `Seed amount too low. Minimum is 100 USDC.` };
|
|
2976
|
+
}
|
|
2977
|
+
return { success: false, error: msg };
|
|
2897
2978
|
}
|
|
2898
2979
|
}
|
|
2899
2980
|
/**
|
|
@@ -9125,7 +9206,7 @@ function loadSecureEnv(basePath, passphrase) {
|
|
|
9125
9206
|
}
|
|
9126
9207
|
|
|
9127
9208
|
// src/index.ts
|
|
9128
|
-
var AGENT_VERSION = "0.1.
|
|
9209
|
+
var AGENT_VERSION = "0.1.41";
|
|
9129
9210
|
// Annotate the CommonJS export names for ESM import in node:
|
|
9130
9211
|
0 && (module.exports = {
|
|
9131
9212
|
AGENT_VERSION,
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exagent/agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.41",
|
|
4
4
|
"description": "Autonomous trading agent runtime for Exagent",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"clean": "rm -rf dist"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@exagent/sdk": "^0.1.
|
|
32
|
+
"@exagent/sdk": "^0.1.17",
|
|
33
33
|
"@nktkas/hyperliquid": "^0.31.0",
|
|
34
34
|
"@polymarket/clob-client": "^4.0.0",
|
|
35
35
|
"chalk": "^5.3.0",
|