@intentlayer/sdk 0.1.0 → 0.1.2
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/{agentConstraintBuilder-CK56UDUI.mjs → agentConstraintBuilder-CWXPHBNY.mjs} +1 -1
- package/dist/{chunk-GRBEB2EV.mjs → chunk-BN6IO64L.mjs} +57 -16
- package/dist/index.d.mts +243 -25
- package/dist/index.d.ts +243 -25
- package/dist/index.js +224 -46
- package/dist/index.mjs +170 -32
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1668,11 +1668,13 @@ function buildV2ConstraintsFromAgent(constraints) {
|
|
|
1668
1668
|
if (constraints.allowedRecipients && constraints.allowedRecipients.length === 1) {
|
|
1669
1669
|
v2Params.allowedRecipient = constraints.allowedRecipients[0];
|
|
1670
1670
|
}
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1671
|
+
const capResolution = resolveCapConfig(constraints);
|
|
1672
|
+
if (capResolution.leafCap) {
|
|
1673
|
+
const asset = constraints.allowedAssets?.[0];
|
|
1674
|
+
v2Params.cap = capToWei(capResolution.leafCap.capValue, asset, constraints);
|
|
1675
|
+
if (capResolution.leafCap.hasPeriod) {
|
|
1676
|
+
v2Params.periodType = "daily";
|
|
1677
|
+
}
|
|
1676
1678
|
}
|
|
1677
1679
|
if (constraints.deadline) {
|
|
1678
1680
|
v2Params.deadline = constraints.deadline;
|
|
@@ -1685,6 +1687,11 @@ function buildV2ConstraintsFromAgent(constraints) {
|
|
|
1685
1687
|
}
|
|
1686
1688
|
const leaf = buildV2LeafFromConstraints(v2Params);
|
|
1687
1689
|
const root = (0, import_viem18.keccak256)(leaf);
|
|
1690
|
+
let dailyCapWei;
|
|
1691
|
+
if (capResolution.dailyCapValue !== void 0) {
|
|
1692
|
+
const asset = constraints.allowedAssets?.[0];
|
|
1693
|
+
dailyCapWei = capToWei(capResolution.dailyCapValue, asset, constraints);
|
|
1694
|
+
}
|
|
1688
1695
|
let recipientLeaves;
|
|
1689
1696
|
if (constraints.allowedRecipients && constraints.allowedRecipients.length === 1) {
|
|
1690
1697
|
const recipient = constraints.allowedRecipients[0].toLowerCase();
|
|
@@ -1692,12 +1699,12 @@ function buildV2ConstraintsFromAgent(constraints) {
|
|
|
1692
1699
|
const key = `${recipient}-${asset}`;
|
|
1693
1700
|
recipientLeaves = { [key]: leaf };
|
|
1694
1701
|
}
|
|
1695
|
-
return { leaf, root, recipientLeaves };
|
|
1702
|
+
return { leaf, root, recipientLeaves, dailyCapWei };
|
|
1696
1703
|
}
|
|
1697
1704
|
function buildMultiRecipientV2Constraints(constraints) {
|
|
1698
1705
|
const recipients = constraints.allowedRecipients;
|
|
1699
1706
|
const builder = new CompoundLeafBuilder();
|
|
1700
|
-
const
|
|
1707
|
+
const capResolution = resolveCapConfig(constraints);
|
|
1701
1708
|
const dummyWallet = "0x0000000000000000000000000000000000000001";
|
|
1702
1709
|
const assets = constraints.allowedAssets;
|
|
1703
1710
|
const hasMultipleAssets = assets && assets.length > 1;
|
|
@@ -1709,7 +1716,7 @@ function buildMultiRecipientV2Constraints(constraints) {
|
|
|
1709
1716
|
recipientAssetCombinations.push({
|
|
1710
1717
|
recipient,
|
|
1711
1718
|
asset,
|
|
1712
|
-
maxAmount:
|
|
1719
|
+
maxAmount: capResolution.leafCap ? capToWei(capResolution.leafCap.capValue, asset, constraints) : void 0,
|
|
1713
1720
|
deadline: constraints.deadline
|
|
1714
1721
|
});
|
|
1715
1722
|
}
|
|
@@ -1717,14 +1724,20 @@ function buildMultiRecipientV2Constraints(constraints) {
|
|
|
1717
1724
|
multiPolicy = builder.createMultiRecipientPolicy(dummyWallet, recipientAssetCombinations);
|
|
1718
1725
|
} else {
|
|
1719
1726
|
const asset = assets?.[0];
|
|
1727
|
+
const cap = capResolution.leafCap ? capToWei(capResolution.leafCap.capValue, asset, constraints) : void 0;
|
|
1720
1728
|
multiPolicy = builder.createMultiRecipientPolicy(dummyWallet, {
|
|
1721
1729
|
allowedRecipients: recipients,
|
|
1722
1730
|
allowedAsset: asset,
|
|
1723
1731
|
maxAmount: cap,
|
|
1724
1732
|
deadline: constraints.deadline,
|
|
1725
|
-
periodCode:
|
|
1733
|
+
periodCode: capResolution.leafCap?.hasPeriod ? PERIOD_DAILY : void 0
|
|
1726
1734
|
});
|
|
1727
1735
|
}
|
|
1736
|
+
let dailyCapWei;
|
|
1737
|
+
if (capResolution.dailyCapValue !== void 0) {
|
|
1738
|
+
const asset = assets?.[0];
|
|
1739
|
+
dailyCapWei = capToWei(capResolution.dailyCapValue, asset, constraints);
|
|
1740
|
+
}
|
|
1728
1741
|
const defaultAsset = assets?.[0] ? assets[0].toLowerCase() : "*";
|
|
1729
1742
|
const defaultKey = `${recipients[0].toLowerCase()}-${defaultAsset}`;
|
|
1730
1743
|
const defaultLeafAndProof = multiPolicy.leafProofs[defaultKey];
|
|
@@ -1735,8 +1748,9 @@ function buildMultiRecipientV2Constraints(constraints) {
|
|
|
1735
1748
|
leaf: defaultLeafAndProof,
|
|
1736
1749
|
// This is actually leafAndProof (leaf + merkle proof)
|
|
1737
1750
|
root: multiPolicy.merkleRoot,
|
|
1738
|
-
recipientLeaves: multiPolicy.leafProofs
|
|
1751
|
+
recipientLeaves: multiPolicy.leafProofs,
|
|
1739
1752
|
// Map of recipient-asset -> leafAndProof
|
|
1753
|
+
dailyCapWei
|
|
1740
1754
|
};
|
|
1741
1755
|
}
|
|
1742
1756
|
function constraintsToV2Params(constraints, recipient) {
|
|
@@ -1746,11 +1760,13 @@ function constraintsToV2Params(constraints, recipient) {
|
|
|
1746
1760
|
} else if (constraints.allowedRecipients && constraints.allowedRecipients.length === 1) {
|
|
1747
1761
|
params.allowedRecipient = constraints.allowedRecipients[0];
|
|
1748
1762
|
}
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1763
|
+
const capResolution = resolveCapConfig(constraints);
|
|
1764
|
+
if (capResolution.leafCap) {
|
|
1765
|
+
const asset = constraints.allowedAssets?.[0];
|
|
1766
|
+
params.cap = capToWei(capResolution.leafCap.capValue, asset, constraints);
|
|
1767
|
+
if (capResolution.leafCap.hasPeriod) {
|
|
1768
|
+
params.periodType = "daily";
|
|
1769
|
+
}
|
|
1754
1770
|
}
|
|
1755
1771
|
if (constraints.deadline) {
|
|
1756
1772
|
params.deadline = constraints.deadline;
|
|
@@ -1763,6 +1779,31 @@ function constraintsToV2Params(constraints, recipient) {
|
|
|
1763
1779
|
}
|
|
1764
1780
|
return params;
|
|
1765
1781
|
}
|
|
1782
|
+
function resolveCapConfig(constraints) {
|
|
1783
|
+
const periodCap = constraints.capPerPeriod ?? constraints.maxDailyUsd;
|
|
1784
|
+
const txCap = constraints.capPerTx ?? constraints.maxPerTxUsd;
|
|
1785
|
+
if (txCap && periodCap) {
|
|
1786
|
+
return {
|
|
1787
|
+
leafCap: { capValue: txCap, hasPeriod: false },
|
|
1788
|
+
dailyCapValue: periodCap
|
|
1789
|
+
};
|
|
1790
|
+
} else if (periodCap) {
|
|
1791
|
+
return {
|
|
1792
|
+
leafCap: { capValue: periodCap, hasPeriod: true },
|
|
1793
|
+
dailyCapValue: void 0
|
|
1794
|
+
};
|
|
1795
|
+
} else if (txCap) {
|
|
1796
|
+
return {
|
|
1797
|
+
leafCap: { capValue: txCap, hasPeriod: false },
|
|
1798
|
+
dailyCapValue: void 0
|
|
1799
|
+
};
|
|
1800
|
+
}
|
|
1801
|
+
return { leafCap: void 0, dailyCapValue: void 0 };
|
|
1802
|
+
}
|
|
1803
|
+
function capToWei(capValue, asset, constraints) {
|
|
1804
|
+
const decimals = asset && constraints.tokenDecimals ? constraints.tokenDecimals[asset.toLowerCase()] ?? 18 : 18;
|
|
1805
|
+
return (0, import_viem18.parseUnits)(String(capValue), decimals);
|
|
1806
|
+
}
|
|
1766
1807
|
function bigintToBytes32(value) {
|
|
1767
1808
|
return `0x${value.toString(16).padStart(64, "0")}`;
|
|
1768
1809
|
}
|
|
@@ -5310,7 +5351,7 @@ var RelayerRuntime = class {
|
|
|
5310
5351
|
*
|
|
5311
5352
|
* @example
|
|
5312
5353
|
* ```ts
|
|
5313
|
-
* import { GLOBAL_FLAG_NO_BRIDGE } from '@
|
|
5354
|
+
* import { GLOBAL_FLAG_NO_BRIDGE } from '@intentlayer/sdk';
|
|
5314
5355
|
*
|
|
5315
5356
|
* // Enable bridge blocking (invalidates pending intents)
|
|
5316
5357
|
* const { headerVersion, txHash } = await runtime.updatePolicyGlobalFlags(
|
|
@@ -5415,13 +5456,16 @@ var IELCloudClient = class {
|
|
|
5415
5456
|
*/
|
|
5416
5457
|
async request(method, path, body) {
|
|
5417
5458
|
const token = await this.getAuthToken();
|
|
5459
|
+
const headers = {
|
|
5460
|
+
Authorization: `Bearer ${token}`
|
|
5461
|
+
};
|
|
5462
|
+
if (body !== void 0) {
|
|
5463
|
+
headers["Content-Type"] = "application/json";
|
|
5464
|
+
}
|
|
5418
5465
|
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
5419
5466
|
method,
|
|
5420
|
-
headers
|
|
5421
|
-
|
|
5422
|
-
"Content-Type": "application/json"
|
|
5423
|
-
},
|
|
5424
|
-
body: body ? JSON.stringify(body) : void 0
|
|
5467
|
+
headers,
|
|
5468
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
5425
5469
|
});
|
|
5426
5470
|
const data = await response.json();
|
|
5427
5471
|
if (!response.ok) {
|
|
@@ -5683,6 +5727,120 @@ var IELCloudClient = class {
|
|
|
5683
5727
|
);
|
|
5684
5728
|
}
|
|
5685
5729
|
// ══════════════════════════════════════════════════════════════════════════
|
|
5730
|
+
// Request Operations (Policy, AgentWallet, Fund)
|
|
5731
|
+
// ══════════════════════════════════════════════════════════════════════════
|
|
5732
|
+
/**
|
|
5733
|
+
* Create a request (policy, agent_wallet, or fund).
|
|
5734
|
+
* Agents use this to request new permissions from the wallet owner.
|
|
5735
|
+
*/
|
|
5736
|
+
async createRequest(body, idempotencyKey) {
|
|
5737
|
+
const token = await this.getAuthToken();
|
|
5738
|
+
const headers = {
|
|
5739
|
+
Authorization: `Bearer ${token}`,
|
|
5740
|
+
"Content-Type": "application/json"
|
|
5741
|
+
};
|
|
5742
|
+
if (idempotencyKey) {
|
|
5743
|
+
headers["Idempotency-Key"] = idempotencyKey;
|
|
5744
|
+
}
|
|
5745
|
+
const response = await fetch(`${this.baseUrl}/v1/requests`, {
|
|
5746
|
+
method: "POST",
|
|
5747
|
+
headers,
|
|
5748
|
+
body: JSON.stringify(body)
|
|
5749
|
+
});
|
|
5750
|
+
const data = await response.json();
|
|
5751
|
+
if (!response.ok) {
|
|
5752
|
+
const error = data;
|
|
5753
|
+
throw new CloudAPIError(
|
|
5754
|
+
response.status,
|
|
5755
|
+
error.code ?? "UNKNOWN_ERROR",
|
|
5756
|
+
error.message ?? "Unknown error",
|
|
5757
|
+
error.details
|
|
5758
|
+
);
|
|
5759
|
+
}
|
|
5760
|
+
return data;
|
|
5761
|
+
}
|
|
5762
|
+
/**
|
|
5763
|
+
* List requests with optional filters.
|
|
5764
|
+
*/
|
|
5765
|
+
async listRequests(options) {
|
|
5766
|
+
const params = new URLSearchParams();
|
|
5767
|
+
if (options?.status) params.set("status", options.status);
|
|
5768
|
+
if (options?.type) params.set("type", options.type);
|
|
5769
|
+
if (options?.walletId) params.set("walletId", options.walletId);
|
|
5770
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
5771
|
+
if (options?.offset) params.set("offset", String(options.offset));
|
|
5772
|
+
const query = params.toString();
|
|
5773
|
+
return this.request(
|
|
5774
|
+
"GET",
|
|
5775
|
+
`/v1/requests${query ? `?${query}` : ""}`
|
|
5776
|
+
);
|
|
5777
|
+
}
|
|
5778
|
+
/**
|
|
5779
|
+
* Get a request by ID.
|
|
5780
|
+
*/
|
|
5781
|
+
async getRequest(requestId) {
|
|
5782
|
+
return this.request("GET", `/v1/requests/${requestId}`);
|
|
5783
|
+
}
|
|
5784
|
+
/**
|
|
5785
|
+
* Get a human-readable summary of a request.
|
|
5786
|
+
*/
|
|
5787
|
+
async getRequestSummary(requestId) {
|
|
5788
|
+
return this.request("GET", `/v1/requests/${requestId}/summary`);
|
|
5789
|
+
}
|
|
5790
|
+
/**
|
|
5791
|
+
* Approve a request. Returns the EIP-712 typed data for the owner to sign.
|
|
5792
|
+
* Only callable by owner (API key holder).
|
|
5793
|
+
*/
|
|
5794
|
+
async approveRequest(requestId) {
|
|
5795
|
+
return this.request(
|
|
5796
|
+
"POST",
|
|
5797
|
+
`/v1/requests/${requestId}/approve`
|
|
5798
|
+
);
|
|
5799
|
+
}
|
|
5800
|
+
/**
|
|
5801
|
+
* Deny a request with an optional reason.
|
|
5802
|
+
* Only callable by owner (API key holder).
|
|
5803
|
+
*/
|
|
5804
|
+
async denyRequest(requestId, reason) {
|
|
5805
|
+
return this.request(
|
|
5806
|
+
"POST",
|
|
5807
|
+
`/v1/requests/${requestId}/deny`,
|
|
5808
|
+
reason ? { reason } : void 0
|
|
5809
|
+
);
|
|
5810
|
+
}
|
|
5811
|
+
/**
|
|
5812
|
+
* Execute an approved request by submitting the owner's EIP-712 signature.
|
|
5813
|
+
* Triggers on-chain execution via the bootstrap pipeline.
|
|
5814
|
+
* Only callable by owner (API key holder).
|
|
5815
|
+
*/
|
|
5816
|
+
async executeRequest(requestId, signature, txHash, policyId, walletAddress) {
|
|
5817
|
+
const body = { signature };
|
|
5818
|
+
if (txHash) body.txHash = txHash;
|
|
5819
|
+
if (policyId) body.policyId = policyId;
|
|
5820
|
+
if (walletAddress) body.walletAddress = walletAddress;
|
|
5821
|
+
return this.request(
|
|
5822
|
+
"POST",
|
|
5823
|
+
`/v1/requests/${requestId}/execute`,
|
|
5824
|
+
body
|
|
5825
|
+
);
|
|
5826
|
+
}
|
|
5827
|
+
/**
|
|
5828
|
+
* Compile policy constraints for a policy request.
|
|
5829
|
+
* Returns the final constraints that will be bootstrapped after approval,
|
|
5830
|
+
* along with any warnings about clamped/excluded items.
|
|
5831
|
+
*
|
|
5832
|
+
* Use this to show users exactly what they're approving before signing.
|
|
5833
|
+
*
|
|
5834
|
+
* @param requestId - Policy request ID
|
|
5835
|
+
* @returns Compiled policy with finalConstraints, warnings, and diff
|
|
5836
|
+
*/
|
|
5837
|
+
async compilePolicyRequest(requestId) {
|
|
5838
|
+
return this.request(
|
|
5839
|
+
"GET",
|
|
5840
|
+
`/v1/requests/${requestId}/compile-policy`
|
|
5841
|
+
);
|
|
5842
|
+
}
|
|
5843
|
+
// ══════════════════════════════════════════════════════════════════════════
|
|
5686
5844
|
// Convenience Methods
|
|
5687
5845
|
// ══════════════════════════════════════════════════════════════════════════
|
|
5688
5846
|
/**
|
|
@@ -6788,6 +6946,8 @@ var CloudRuntimeClient = class {
|
|
|
6788
6946
|
nonce,
|
|
6789
6947
|
policyId,
|
|
6790
6948
|
root: v2Result.root,
|
|
6949
|
+
dailyCap: v2Result.dailyCapWei,
|
|
6950
|
+
// Policy-level daily cap (dual-cap: capPerTx in leaf + capPerPeriod here)
|
|
6791
6951
|
delegate: params.delegate ?? this.runtime.defaultDelegate,
|
|
6792
6952
|
validFor: 3600,
|
|
6793
6953
|
// 1 hour validity
|
|
@@ -7407,7 +7567,6 @@ init_v2LeafBuilder();
|
|
|
7407
7567
|
// src/policy/policyHeaderBuilder.ts
|
|
7408
7568
|
var import_viem21 = require("viem");
|
|
7409
7569
|
init_types();
|
|
7410
|
-
init_types();
|
|
7411
7570
|
function stringLabelToBytes32(label) {
|
|
7412
7571
|
const bytes = (0, import_viem21.stringToBytes)(label);
|
|
7413
7572
|
if (bytes.length > 32) {
|
|
@@ -7794,7 +7953,7 @@ async function combinedBootstrap(config, runtime) {
|
|
|
7794
7953
|
if (constraints.forbidBridges) {
|
|
7795
7954
|
globalFlags |= GLOBAL_FLAG_NO_BRIDGE;
|
|
7796
7955
|
}
|
|
7797
|
-
const dailyCap = dailyCapWei ?? (constraints.maxDailyUsd ? (0, import_viem23.parseEther)(String(constraints.maxDailyUsd)) : 0n);
|
|
7956
|
+
const dailyCap = dailyCapWei ?? v2Result.dailyCapWei ?? (constraints.maxDailyUsd ? (0, import_viem23.parseEther)(String(constraints.maxDailyUsd)) : 0n);
|
|
7798
7957
|
const nonce = await runtime.getNonce(walletAddress);
|
|
7799
7958
|
const currentTimestamp = await runtime.getCurrentTimestamp();
|
|
7800
7959
|
const needsVendorHeader = constraints.vendorMembershipRequired && constraints.vendorRegistry;
|
|
@@ -7913,7 +8072,7 @@ async function createSubWallet(params, runtime) {
|
|
|
7913
8072
|
const walletAddress = await runtime.predictWalletAddress(params.parentWallet, salt);
|
|
7914
8073
|
const isDeployed = await runtime.isWalletDeployed(walletAddress);
|
|
7915
8074
|
if (!isDeployed) {
|
|
7916
|
-
await runtime.deployWallet(params.parentWallet, salt);
|
|
8075
|
+
await runtime.deployWallet(params.parentWallet, salt, params.agentName);
|
|
7917
8076
|
}
|
|
7918
8077
|
const constraintData = buildAgentConstraints(
|
|
7919
8078
|
params.constraints,
|
|
@@ -7945,7 +8104,8 @@ async function createSubWallet(params, runtime) {
|
|
|
7945
8104
|
if (params.constraints.forbidBridges && !constraintsRequireV3(params.constraints)) {
|
|
7946
8105
|
globalFlags |= GLOBAL_FLAG_NO_BRIDGE;
|
|
7947
8106
|
}
|
|
7948
|
-
const
|
|
8107
|
+
const capValue = params.constraints.capPerPeriod ?? params.constraints.maxDailyUsd;
|
|
8108
|
+
const dailyCapWei = capValue ? (0, import_viem24.parseEther)(String(capValue)) : 0n;
|
|
7949
8109
|
const bootstrapIntent = buildMinimalPolicyBootstrapIntent({
|
|
7950
8110
|
wallet: walletAddress,
|
|
7951
8111
|
chainId: BigInt(runtime.chainId),
|
|
@@ -9214,8 +9374,9 @@ function buildPresetSummary(type, description, constraints) {
|
|
|
9214
9374
|
if (constraints.allowedRecipients) {
|
|
9215
9375
|
summary.recipients = constraints.allowedRecipients.map(formatAddress);
|
|
9216
9376
|
}
|
|
9217
|
-
|
|
9218
|
-
|
|
9377
|
+
const capValue = constraints.capPerPeriod ?? constraints.maxDailyUsd;
|
|
9378
|
+
if (capValue) {
|
|
9379
|
+
summary.cap = formatUsd(capValue);
|
|
9219
9380
|
summary.period = getPeriodName(constraints.periodCode);
|
|
9220
9381
|
}
|
|
9221
9382
|
if (constraints.bucketId) {
|
|
@@ -9265,6 +9426,7 @@ var SELECTORS = {
|
|
|
9265
9426
|
UNISWAP_EXACT_OUTPUT_SINGLE: "0xdb3e2198"
|
|
9266
9427
|
};
|
|
9267
9428
|
function tradingAgent(config) {
|
|
9429
|
+
const cap = config.capPerPeriod ?? config.maxDailyUsd;
|
|
9268
9430
|
const venueTargets = [config.swapContract];
|
|
9269
9431
|
const venueSelectors = [...config.swapSelectors ?? []];
|
|
9270
9432
|
if (config.treasuryReturn) {
|
|
@@ -9275,8 +9437,9 @@ function tradingAgent(config) {
|
|
|
9275
9437
|
venueSelectors.push(SELECTORS.TRANSFER);
|
|
9276
9438
|
}
|
|
9277
9439
|
return {
|
|
9278
|
-
|
|
9440
|
+
capPerPeriod: cap,
|
|
9279
9441
|
allowedRecipients: config.treasuryReturn ? [config.treasuryReturn] : void 0,
|
|
9442
|
+
allowedAssets: config.tokenContract ? [config.tokenContract] : void 0,
|
|
9280
9443
|
venueTargets,
|
|
9281
9444
|
venueSelectors,
|
|
9282
9445
|
// Multi-op format now supports venue validation:
|
|
@@ -9294,9 +9457,11 @@ function paymentAgent(config) {
|
|
|
9294
9457
|
venueTargets.push(config.tokenContract);
|
|
9295
9458
|
venueSelectors.push(SELECTORS.TRANSFER);
|
|
9296
9459
|
}
|
|
9460
|
+
const cap = config.capPerPeriod ?? config.maxDailyUsd;
|
|
9297
9461
|
return {
|
|
9298
9462
|
allowedRecipients: config.vendors,
|
|
9299
|
-
|
|
9463
|
+
allowedAssets: config.tokenContract ? [config.tokenContract] : void 0,
|
|
9464
|
+
capPerPeriod: cap,
|
|
9300
9465
|
venueTargets,
|
|
9301
9466
|
venueSelectors,
|
|
9302
9467
|
requireVenue: true
|
|
@@ -9304,6 +9469,9 @@ function paymentAgent(config) {
|
|
|
9304
9469
|
};
|
|
9305
9470
|
}
|
|
9306
9471
|
function treasuryOps(config) {
|
|
9472
|
+
if (config.tokenContracts && config.tokenContracts.length === 0) {
|
|
9473
|
+
throw new Error("treasuryOps: tokenContracts must not be empty when provided");
|
|
9474
|
+
}
|
|
9307
9475
|
const venueTargets = [...config.protocolContracts];
|
|
9308
9476
|
const venueSelectors = [...config.protocolSelectors];
|
|
9309
9477
|
if (config.treasuryAddresses) {
|
|
@@ -9314,14 +9482,16 @@ function treasuryOps(config) {
|
|
|
9314
9482
|
venueSelectors.push(SELECTORS.TRANSFER);
|
|
9315
9483
|
venueSelectors.push(SELECTORS.APPROVE);
|
|
9316
9484
|
}
|
|
9485
|
+
const cap = config.capPerPeriod ?? config.maxDailyUsd;
|
|
9317
9486
|
const protocolCount = config.protocolContracts.length;
|
|
9318
9487
|
const bridgeStatus = config.allowBridges ? "" : ", NO_BRIDGE";
|
|
9319
|
-
const description = `Treasury Ops: ${protocolCount} protocols, ${
|
|
9488
|
+
const description = `Treasury Ops: ${protocolCount} protocols, ${cap ?? "?"}/day${bridgeStatus}`;
|
|
9320
9489
|
const constraints = {
|
|
9321
9490
|
description,
|
|
9322
9491
|
presetType: "treasuryOps",
|
|
9323
|
-
|
|
9492
|
+
capPerPeriod: cap,
|
|
9324
9493
|
allowedRecipients: config.treasuryAddresses,
|
|
9494
|
+
allowedAssets: config.tokenContracts,
|
|
9325
9495
|
venueTargets,
|
|
9326
9496
|
venueSelectors,
|
|
9327
9497
|
// Multi-op format now supports venue validation:
|
|
@@ -9335,6 +9505,9 @@ function treasuryOps(config) {
|
|
|
9335
9505
|
return constraints;
|
|
9336
9506
|
}
|
|
9337
9507
|
function lendingOps(config) {
|
|
9508
|
+
if (!config.tokenContracts || config.tokenContracts.length === 0) {
|
|
9509
|
+
throw new Error("lendingOps requires at least one token contract");
|
|
9510
|
+
}
|
|
9338
9511
|
const lendingSelectors = config.lendingSelectors ?? [
|
|
9339
9512
|
SELECTORS.AAVE_SUPPLY,
|
|
9340
9513
|
SELECTORS.AAVE_WITHDRAW,
|
|
@@ -9348,17 +9521,19 @@ function lendingOps(config) {
|
|
|
9348
9521
|
venueSelectors.push(SELECTORS.APPROVE);
|
|
9349
9522
|
venueSelectors.push(SELECTORS.TRANSFER);
|
|
9350
9523
|
}
|
|
9524
|
+
const cap = config.capPerPeriod ?? config.maxDailyUsd;
|
|
9351
9525
|
const tokenCount = config.tokenContracts?.length ?? 0;
|
|
9352
9526
|
const bridgeStatus = config.allowBridges ? "" : ", NO_BRIDGE";
|
|
9353
|
-
const description = `Lending Ops: ${tokenCount} tokens, ${
|
|
9527
|
+
const description = `Lending Ops: ${tokenCount} tokens, ${cap ?? "?"}/day${bridgeStatus}`;
|
|
9354
9528
|
const constraints = {
|
|
9355
9529
|
description,
|
|
9356
9530
|
presetType: "lendingOps",
|
|
9357
|
-
|
|
9531
|
+
capPerPeriod: cap,
|
|
9358
9532
|
venueTargets,
|
|
9359
9533
|
venueSelectors,
|
|
9360
9534
|
requireVenue: true,
|
|
9361
|
-
forbidBridges: !config.allowBridges
|
|
9535
|
+
forbidBridges: !config.allowBridges,
|
|
9536
|
+
allowedAssets: config.tokenContracts
|
|
9362
9537
|
};
|
|
9363
9538
|
logPresetSummary(buildPresetSummary("Lending Ops", description, constraints));
|
|
9364
9539
|
return constraints;
|
|
@@ -9366,13 +9541,14 @@ function lendingOps(config) {
|
|
|
9366
9541
|
function stablecoinTransfer(config) {
|
|
9367
9542
|
const venueTargets = [...config.stablecoins];
|
|
9368
9543
|
const venueSelectors = [SELECTORS.TRANSFER];
|
|
9544
|
+
const cap = config.capPerPeriod ?? config.maxDailyUsd;
|
|
9369
9545
|
const recipientCount = config.recipients.length;
|
|
9370
9546
|
const stablecoinCount = config.stablecoins.length;
|
|
9371
|
-
const description = `Stablecoin Transfer: ${recipientCount} recipients, ${stablecoinCount} stablecoins, ${
|
|
9547
|
+
const description = `Stablecoin Transfer: ${recipientCount} recipients, ${stablecoinCount} stablecoins, ${cap ?? "?"}/day`;
|
|
9372
9548
|
const constraints = {
|
|
9373
9549
|
description,
|
|
9374
9550
|
presetType: "stablecoinTransfer",
|
|
9375
|
-
|
|
9551
|
+
capPerPeriod: cap,
|
|
9376
9552
|
allowedRecipients: config.recipients,
|
|
9377
9553
|
allowedAssets: config.stablecoins,
|
|
9378
9554
|
venueTargets,
|
|
@@ -9402,15 +9578,15 @@ function payroll(config) {
|
|
|
9402
9578
|
venueTargets.push(config.tokenContract);
|
|
9403
9579
|
venueSelectors.push(SELECTORS.TRANSFER);
|
|
9404
9580
|
}
|
|
9581
|
+
const cap = config.capPerPeriod ?? config.maxMonthlyUsd;
|
|
9405
9582
|
const employeeCount = config.employees.length;
|
|
9406
|
-
const description = `Payroll: ${employeeCount} employees, ${
|
|
9583
|
+
const description = `Payroll: ${employeeCount} employees, ${cap ?? "?"}/month`;
|
|
9407
9584
|
const constraints = {
|
|
9408
9585
|
description,
|
|
9409
9586
|
presetType: "payroll",
|
|
9410
9587
|
allowedRecipients: config.employees,
|
|
9411
9588
|
allowedAssets,
|
|
9412
|
-
|
|
9413
|
-
maxDailyUsd: config.maxMonthlyUsd,
|
|
9589
|
+
capPerPeriod: cap,
|
|
9414
9590
|
periodCode: PERIOD_MONTH30,
|
|
9415
9591
|
periodOffsetMinutes: 0,
|
|
9416
9592
|
// UTC
|
|
@@ -9439,12 +9615,13 @@ function transferOnly(config) {
|
|
|
9439
9615
|
venueTargets.push(config.tokenContract);
|
|
9440
9616
|
venueSelectors.push(SELECTORS.TRANSFER);
|
|
9441
9617
|
}
|
|
9618
|
+
const cap = config.capPerPeriod ?? config.maxDailyUsd;
|
|
9442
9619
|
const recipientCount = config.recipients.length;
|
|
9443
|
-
const description = `Transfer Only: ${recipientCount} recipients, ${
|
|
9620
|
+
const description = `Transfer Only: ${recipientCount} recipients, ${cap ?? "?"}/day`;
|
|
9444
9621
|
const constraints = {
|
|
9445
9622
|
description,
|
|
9446
9623
|
presetType: "transferOnly",
|
|
9447
|
-
|
|
9624
|
+
capPerPeriod: cap,
|
|
9448
9625
|
allowedRecipients: config.recipients,
|
|
9449
9626
|
allowedAssets,
|
|
9450
9627
|
venueTargets,
|
|
@@ -9462,15 +9639,15 @@ function marketingBucket(config) {
|
|
|
9462
9639
|
venueSelectors.push(SELECTORS.TRANSFER);
|
|
9463
9640
|
}
|
|
9464
9641
|
const bucketIdHex = config.bucketId.startsWith("0x") && config.bucketId.length === 66 ? config.bucketId : (0, import_viem27.keccak256)((0, import_viem27.toHex)(config.bucketId));
|
|
9642
|
+
const cap = config.capPerPeriod ?? config.maxMonthlyUsd;
|
|
9465
9643
|
const recipientCount = config.recipients.length;
|
|
9466
9644
|
const bucketName = typeof config.bucketId === "string" && !config.bucketId.startsWith("0x") ? config.bucketId : bucketIdHex.slice(0, 10) + "...";
|
|
9467
|
-
const description = `Marketing: ${recipientCount} vendors share ${
|
|
9645
|
+
const description = `Marketing: ${recipientCount} vendors share ${cap ?? "?"}/month`;
|
|
9468
9646
|
const constraints = {
|
|
9469
9647
|
description,
|
|
9470
9648
|
presetType: "marketingBucket",
|
|
9471
9649
|
allowedRecipients: config.recipients,
|
|
9472
|
-
|
|
9473
|
-
maxDailyUsd: config.maxMonthlyUsd,
|
|
9650
|
+
capPerPeriod: cap,
|
|
9474
9651
|
periodCode: PERIOD_MONTH30,
|
|
9475
9652
|
periodOffsetMinutes: 0,
|
|
9476
9653
|
bucketId: bucketIdHex,
|
|
@@ -9490,13 +9667,14 @@ function vendorCard(config) {
|
|
|
9490
9667
|
}
|
|
9491
9668
|
const vendorGroupIdBigint = typeof config.vendorGroupId === "bigint" ? config.vendorGroupId : BigInt(config.vendorGroupId);
|
|
9492
9669
|
const hasVendorRegistry = config.vendorRegistry && config.vendorProfileId;
|
|
9670
|
+
const cap = config.capPerPeriod ?? config.maxDailyUsd;
|
|
9493
9671
|
const vendorProof = hasVendorRegistry ? " (with Merkle proof)" : "";
|
|
9494
|
-
const description = `Vendor Card: Dynamic vendor list, ${
|
|
9672
|
+
const description = `Vendor Card: Dynamic vendor list, ${cap ?? "?"}/day${vendorProof}`;
|
|
9495
9673
|
const constraints = {
|
|
9496
9674
|
description,
|
|
9497
9675
|
presetType: "vendorCard",
|
|
9498
9676
|
vendorGroupId: vendorGroupIdBigint,
|
|
9499
|
-
|
|
9677
|
+
capPerPeriod: cap,
|
|
9500
9678
|
periodCode: PERIOD_DAILY,
|
|
9501
9679
|
periodOffsetMinutes: 0,
|
|
9502
9680
|
venueTargets: venueTargets.length > 0 ? venueTargets : void 0,
|