@dev.sail.money/sailor 0.0.2-31 → 0.1.0-local
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/AGENTS.md +140 -140
- package/LICENSE +21 -21
- package/README.md +430 -430
- package/docs/PERMISSION_MODEL.md +93 -93
- package/examples/permissions/BoundedApproveAndCallBatch.sol +179 -179
- package/examples/permissions/BoundedBet_Limitless_Base.sol +97 -97
- package/examples/permissions/BoundedBorrow_AaveV3_Arbitrum.sol +94 -94
- package/examples/permissions/BoundedPerp_GMXv2_Arbitrum.sol +154 -154
- package/examples/permissions/BoundedStake_Venice_Base.sol +85 -85
- package/examples/permissions/BoundedSupply_AaveV3_Arbitrum.sol +82 -82
- package/examples/permissions/BoundedSwap_UniswapV3_Base.sol +116 -116
- package/examples/permissions/BoundedSwap_UniswapV4_Unichain.sol +150 -150
- package/examples/permissions/BoundedTransfer_ERC20_Ethereum.sol +73 -73
- package/examples/permissions/BoundedVault_ERC4626_Base.sol +97 -97
- package/examples/permissions/README.md +79 -79
- package/examples/permissions/SailCalldata.sol +118 -118
- package/examples/permissions/foundry.toml +10 -10
- package/examples/permissions/interfaces/IBatchPermission.sol +38 -38
- package/examples/permissions/interfaces/IPermission.sol +18 -18
- package/package.json +45 -45
- package/packages/cli/README.md +34 -34
- package/packages/cli/dist/index.cjs +705 -687
- package/packages/cli/dist/server.cjs +506 -495
- package/packages/sdk/README.md +65 -65
- package/packages/sdk/dist/intelligence.d.ts +1 -1
- package/packages/sdk/dist/intelligence.js +1 -1
- package/packages/sdk/package.json +80 -80
- package/packages/ui/dist/assets/{add-B0J2XPqD.js → add-BxpXfVWe.js} +1 -1
- package/packages/ui/dist/assets/{all-wallets-DAWTUGbI.js → all-wallets-BKTn_sWK.js} +1 -1
- package/packages/ui/dist/assets/{app-store-B-bz9zO1.js → app-store-CfuKbwxR.js} +1 -1
- package/packages/ui/dist/assets/{apple-CW_aatUl.js → apple-BKSBbNYg.js} +1 -1
- package/packages/ui/dist/assets/{arrow-bottom-D9xphoWP.js → arrow-bottom-D4bG6gZi.js} +1 -1
- package/packages/ui/dist/assets/{arrow-bottom-circle-D-N3HlXh.js → arrow-bottom-circle-BNTs1p0T.js} +1 -1
- package/packages/ui/dist/assets/{arrow-left-DofAd9ta.js → arrow-left-2uee3vYv.js} +1 -1
- package/packages/ui/dist/assets/{arrow-right-CLBZVLVF.js → arrow-right-BktjMV6h.js} +1 -1
- package/packages/ui/dist/assets/{arrow-top-B47Y4sI6.js → arrow-top-Izu28fX4.js} +1 -1
- package/packages/ui/dist/assets/{bank-CVHPZeNC.js → bank-USBaAyFM.js} +1 -1
- package/packages/ui/dist/assets/{basic-CijTV8XG.js → basic-C_9KjTEH.js} +1 -1
- package/packages/ui/dist/assets/{browser-D12J6hPl.js → browser-DAEMAKV7.js} +1 -1
- package/packages/ui/dist/assets/{card-suad8wBG.js → card-DT8yDkKN.js} +1 -1
- package/packages/ui/dist/assets/{ccip-Bev57e2Y.js → ccip-CkqfGSxX.js} +1 -1
- package/packages/ui/dist/assets/{checkmark-DSzbM9ge.js → checkmark-CsgdEXFj.js} +1 -1
- package/packages/ui/dist/assets/{checkmark-bold-Ctlpy8fR.js → checkmark-bold-D2gjOQo2.js} +1 -1
- package/packages/ui/dist/assets/{chevron-bottom-DD4PYpsh.js → chevron-bottom-tprFynYV.js} +1 -1
- package/packages/ui/dist/assets/{chevron-left-HJzgI5fr.js → chevron-left-D2Zj1gNB.js} +1 -1
- package/packages/ui/dist/assets/{chevron-right-BAJMtoWG.js → chevron-right-D1rRuAVe.js} +1 -1
- package/packages/ui/dist/assets/{chevron-top-CSTGBRNq.js → chevron-top-24dL1mbL.js} +1 -1
- package/packages/ui/dist/assets/{chrome-store-CSgmzP0o.js → chrome-store-Vy-5niYX.js} +1 -1
- package/packages/ui/dist/assets/{clock-BGKXrbjA.js → clock-qBjLnVdJ.js} +1 -1
- package/packages/ui/dist/assets/{close-B-9LI-cc.js → close-DARDwgcu.js} +1 -1
- package/packages/ui/dist/assets/{coinPlaceholder-C9zB6O8f.js → coinPlaceholder-BvpIbPlD.js} +1 -1
- package/packages/ui/dist/assets/{compass-DNbNVsgN.js → compass-BMTO0ayt.js} +1 -1
- package/packages/ui/dist/assets/{copy-r_J027hY.js → copy-PaXeRHza.js} +1 -1
- package/packages/ui/dist/assets/{core-CuWvvvu4.js → core-BFnStQd-.js} +3 -3
- package/packages/ui/dist/assets/cursor-BDvw-B17.js +3 -0
- package/packages/ui/dist/assets/{cursor-transparent-By6KxbOE.js → cursor-transparent-BEMdi-8q.js} +1 -1
- package/packages/ui/dist/assets/{desktop-DRMmsjrd.js → desktop-CfuLLThw.js} +1 -1
- package/packages/ui/dist/assets/{disconnect-C69Z8KUW.js → disconnect-DhwgJMiR.js} +1 -1
- package/packages/ui/dist/assets/{discord-p3AKvqDk.js → discord-po8qoN1s.js} +1 -1
- package/packages/ui/dist/assets/{etherscan-C2zTiWaN.js → etherscan-BEsz0_yx.js} +1 -1
- package/packages/ui/dist/assets/{events-DKTfpIHs.js → events-Bz33Unzu.js} +1 -1
- package/packages/ui/dist/assets/{exclamation-triangle-D4IJznwI.js → exclamation-triangle-7CjTAGOQ.js} +1 -1
- package/packages/ui/dist/assets/{extension-C0y2g1tg.js → extension-CmxjEWEt.js} +1 -1
- package/packages/ui/dist/assets/{external-link-fkbBBTcW.js → external-link-CmQ--bNS.js} +1 -1
- package/packages/ui/dist/assets/{facebook-nsIgKROR.js → facebook-CIBn9b65.js} +1 -1
- package/packages/ui/dist/assets/{fallback-DHv3hSPW.js → fallback-DATyrQlb.js} +1 -1
- package/packages/ui/dist/assets/{farcaster-CzBHn8fo.js → farcaster-OJ3Jasxg.js} +1 -1
- package/packages/ui/dist/assets/{filters-gW1TGI8D.js → filters-D4x09zeL.js} +1 -1
- package/packages/ui/dist/assets/{github-D9UuzE25.js → github-ZlIuMArp.js} +1 -1
- package/packages/ui/dist/assets/{google-DxUfChw6.js → google-Gwg85sfv.js} +1 -1
- package/packages/ui/dist/assets/{help-circle-2dNDsXrX.js → help-circle-D1uOWYcX.js} +1 -1
- package/packages/ui/dist/assets/{id-rNBDU8mz.js → id-C0-5UdYk.js} +1 -1
- package/packages/ui/dist/assets/{image-C9Peu4QW.js → image-D_DUsv8-.js} +1 -1
- package/packages/ui/dist/assets/{index-B1wosqUU.js → index-BCzex_R6.js} +1 -1
- package/packages/ui/dist/assets/index-BUhrHLpY.js +1775 -0
- package/packages/ui/dist/assets/index-Cq02kQmy.css +1 -0
- package/packages/ui/dist/assets/{index-B1aFIpJ0.js → index-CrYzBWfD.js} +1 -1
- package/packages/ui/dist/assets/{index-_F9WbMAT.js → index-DdbJhIdl.js} +3 -3
- package/packages/ui/dist/assets/{index-JwrWbcaz.js → index-DiojfeVM.js} +1 -1
- package/packages/ui/dist/assets/{index-4lrTXbkY.js → index-izd7vu_r.js} +1 -1
- package/packages/ui/dist/assets/{index.es-wlYgJouQ.js → index.es-DdkHhQAj.js} +4 -4
- package/packages/ui/dist/assets/{info-cGbqKpFv.js → info-CiRd_kEG.js} +1 -1
- package/packages/ui/dist/assets/{info-circle-B8Xfr9A0.js → info-circle-ypxjqarK.js} +1 -1
- package/packages/ui/dist/assets/{lightbulb-CM2m-PnZ.js → lightbulb-B-pxLxd8.js} +1 -1
- package/packages/ui/dist/assets/{mail-_qO7Zcxu.js → mail-BYmicuVZ.js} +1 -1
- package/packages/ui/dist/assets/{metamask-sdk-Dy961bnw.js → metamask-sdk-Ccl6DG7Q.js} +1 -1
- package/packages/ui/dist/assets/{mobile-C6TDJh2K.js → mobile-CtP5PqVT.js} +1 -1
- package/packages/ui/dist/assets/{more-3pPTR0Gx.js → more-6C2733we.js} +1 -1
- package/packages/ui/dist/assets/{network-placeholder-BtFT2yZA.js → network-placeholder-CdhxMzqd.js} +1 -1
- package/packages/ui/dist/assets/{nftPlaceholder-BfBZEH1N.js → nftPlaceholder-DVmTWEAY.js} +1 -1
- package/packages/ui/dist/assets/{off-Bg5cnmyC.js → off-DNYLughs.js} +1 -1
- package/packages/ui/dist/assets/{parseSignature-CSIsnC1G.js → parseSignature-Dq2B5Bu3.js} +1 -1
- package/packages/ui/dist/assets/{play-store-Dg32m5PL.js → play-store-D7Qut5ta.js} +1 -1
- package/packages/ui/dist/assets/{plus-Ce97GbOa.js → plus-kqMyjt3q.js} +1 -1
- package/packages/ui/dist/assets/{qr-code-D3KdZWUh.js → qr-code-DiUCWRbz.js} +1 -1
- package/packages/ui/dist/assets/{recycle-horizontal-DOKfyzVh.js → recycle-horizontal-Boe3XiS-.js} +1 -1
- package/packages/ui/dist/assets/{refresh-DSjW7q17.js → refresh-CrBgBQYO.js} +1 -1
- package/packages/ui/dist/assets/{reown-logo-B0n-8waR.js → reown-logo-CFZCCHSx.js} +1 -1
- package/packages/ui/dist/assets/{search-CL2iyGid.js → search-ChTDrghU.js} +1 -1
- package/packages/ui/dist/assets/{secp256k1-DdqDRGog.js → secp256k1-DAV5Q_FR.js} +1 -1
- package/packages/ui/dist/assets/{send-C_Rm4fzj.js → send-DLFbBFe1.js} +1 -1
- package/packages/ui/dist/assets/{swapHorizontal-0d_94RdY.js → swapHorizontal-BEs3emfG.js} +1 -1
- package/packages/ui/dist/assets/{swapHorizontalBold-BukSRa8V.js → swapHorizontalBold-CC-Hfa7W.js} +1 -1
- package/packages/ui/dist/assets/{swapHorizontalMedium-DvroDkEf.js → swapHorizontalMedium-BmR0H8DC.js} +1 -1
- package/packages/ui/dist/assets/{swapHorizontalRoundedBold-BAehcn9y.js → swapHorizontalRoundedBold-BdP5NGIH.js} +1 -1
- package/packages/ui/dist/assets/{swapVertical-kblIte_7.js → swapVertical-CPrGEJPY.js} +1 -1
- package/packages/ui/dist/assets/{telegram-DHLO89MI.js → telegram-CxNoZ80Q.js} +1 -1
- package/packages/ui/dist/assets/{three-dots-ctb5FHLw.js → three-dots-BRa6SBpL.js} +1 -1
- package/packages/ui/dist/assets/{twitch-CK_fCqNu.js → twitch-BC338bG5.js} +1 -1
- package/packages/ui/dist/assets/{twitterIcon-BCngN3WD.js → twitterIcon-BGZmt2i9.js} +1 -1
- package/packages/ui/dist/assets/{verify-Dy-B59vy.js → verify-CEstW0zw.js} +1 -1
- package/packages/ui/dist/assets/{verify-filled-DHDHx8Lk.js → verify-filled-OkZb0weU.js} +1 -1
- package/packages/ui/dist/assets/{w3m-modal-DRNXP3Ww.js → w3m-modal-pS09ECwE.js} +1 -1
- package/packages/ui/dist/assets/{wallet-DriPOF7d.js → wallet-BXVKCgC9.js} +1 -1
- package/packages/ui/dist/assets/{wallet-placeholder-B4ukOjpR.js → wallet-placeholder-C_kNhB1c.js} +1 -1
- package/packages/ui/dist/assets/{walletconnect-Cjl1Ki75.js → walletconnect-CRKIuUHH.js} +1 -1
- package/packages/ui/dist/assets/{warning-circle-C7eCTFhJ.js → warning-circle-DB2NnwlJ.js} +1 -1
- package/packages/ui/dist/assets/{x-B8jYZY9t.js → x-DT4RmwL5.js} +1 -1
- package/packages/ui/dist/index.html +14 -14
- package/scripts/check-docs.mjs +262 -262
- package/scripts/check-init.mjs +108 -108
- package/scripts/postinstall.js +81 -56
- package/templates/custom-mandate/.sail/contracts/interfaces/IPermission.sol +18 -18
- package/templates/custom-mandate/README.md +116 -116
- package/templates/custom-mandate/foundry.toml +8 -8
- package/templates/custom-mandate/mandates/BoundedCallPermission.sol +41 -41
- package/templates/custom-mandate/mandates/README.md +16 -16
- package/templates/custom-mandate/mandates/SailCalldata.sol +118 -118
- package/templates/default/.cursor/rules +25 -25
- package/templates/default/.env.example +20 -20
- package/templates/default/.github/workflows/agent-tick.yml +33 -33
- package/templates/default/.sail/README.md +13 -13
- package/templates/default/.sail/config.json +10 -10
- package/templates/default/AGENTS.md +171 -171
- package/templates/default/CLAUDE.md +2 -2
- package/templates/default/README.md +16 -16
- package/templates/default/_gitignore +13 -13
- package/templates/default/docs/PERMISSION_MODEL.md +93 -93
- package/templates/default/examples/dca/README.md +16 -16
- package/templates/default/examples/dca/agent.ts +174 -174
- package/templates/default/examples/dca/mandate.ts +45 -45
- package/templates/default/package.json +17 -17
- package/templates/default/src/agent.ts +37 -37
- package/templates/default/src/config.ts +24 -24
- package/templates/default/src/mandate.ts +22 -22
- package/templates/default/tsconfig.json +17 -17
- package/templates/default/ui/README.md +3 -3
- package/templates/lifi-permissions/LifiBoundedApprovePermissionCloneable.sol +84 -84
- package/templates/lifi-permissions/LifiDiamondSwapPermissionCloneable.sol +97 -97
- package/templates/lifi-permissions/README.md +53 -53
- package/packages/ui/dist/assets/cursor-0ZcCqvYy.js +0 -3
- package/packages/ui/dist/assets/index-BzT0MJhc.js +0 -1775
- package/packages/ui/dist/assets/index-n8bp1ZEc.css +0 -1
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity 0.8.26;
|
|
3
|
-
|
|
4
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
-
// Protocol : Uniswap V4
|
|
6
|
-
// Version : Universal Router + PoolManager (V4 singleton)
|
|
7
|
-
// NOTE: V4 is NOT the same as V3. Calldata encoding is completely
|
|
8
|
-
// different — do NOT adapt a V3 permission for V4.
|
|
9
|
-
// Chain : Unichain mainnet
|
|
10
|
-
// Target : Universal Router 0xef740bf23acae26f6492b10de645d6b98dc8eaf3
|
|
11
|
-
// (verify on Uniscan before use)
|
|
12
|
-
//
|
|
13
|
-
// ENFORCES ON-CHAIN (kernel calls evaluate() on every dispatch; false ⇒ dispatch blocked):
|
|
14
|
-
// execute(bytes,bytes[],uint256) selector 0x3593564c / execute(bytes,bytes[]) selector 0x24856bc3
|
|
15
|
-
// • target must be UNIVERSAL_ROUTER
|
|
16
|
-
// • first command byte (masking the allow-failure MSB) must be V4_SWAP (0x10)
|
|
17
|
-
// • exactly one command (single-swap path — disallow multi-hop command strings)
|
|
18
|
-
// • V4 action inside must be SWAP_EXACT_IN_SINGLE (0x00)
|
|
19
|
-
// • tokenIn (from poolKey, derived by zeroForOne) must be FIXED_CURRENCY_IN
|
|
20
|
-
// • tokenOut must be in ALLOWED_CURRENCIES_OUT
|
|
21
|
-
// • amountIn ≤ MAX_AMOUNT_IN
|
|
22
|
-
// • amountOutMinimum ≥ amountIn × MIN_BPS / 10 000 (slippage floor — see caveat below)
|
|
23
|
-
//
|
|
24
|
-
// AGENT-ENFORCED / NOT BOUNDED HERE (off-chain — can change without redeploying this contract):
|
|
25
|
-
// • real (cross-denomination) slippage — see MIN_BPS caveat in evaluate()
|
|
26
|
-
// • swap frequency / cadence
|
|
27
|
-
//
|
|
28
|
-
// DOCUMENTED LIMITATIONS (on-chain, but intentionally not constrained):
|
|
29
|
-
// • hookData is not inspected (hooks can alter swap behavior on-chain; if the
|
|
30
|
-
// pool uses a hook that significantly changes execution, this permission cannot
|
|
31
|
-
// constrain it. Deploy against pools with address(0) hooks or audited hooks only.)
|
|
32
|
-
// • fee tier and tickSpacing within the PoolKey are not constrained here
|
|
33
|
-
// (add pool-key checks if you want to restrict to a specific pool)
|
|
34
|
-
// • The ALL_CURRENCY_PAIR constant (FIXED_CURRENCY_IN, allowedCurrenciesOut) does
|
|
35
|
-
// not constrain which pool is used when multiple pools share the same currency pair
|
|
36
|
-
//
|
|
37
|
-
// VERIFY BEFORE USE:
|
|
38
|
-
// • Confirm Universal Router address on Unichain (shown above; verify on Uniscan).
|
|
39
|
-
// • V4_SWAP command byte = 0x10, SWAP_EXACT_IN_SINGLE action = 0x00 — verify
|
|
40
|
-
// against deployed UniversalRouter and V4Router on Unichain if contract is updated.
|
|
41
|
-
// • PoolKey struct layout (currency0, currency1, fee, tickSpacing, hooks) must
|
|
42
|
-
// match the deployed PoolManager on Unichain. If layout changes, update struct.
|
|
43
|
-
// • hookData is not bounded. Only use with unhookyed pools or audited, bounded hooks.
|
|
44
|
-
// • Calldata revert = false (kernel treats revert as denial) — malformed inputs
|
|
45
|
-
// are safely rejected, but verify with actual calldata samples before deployment.
|
|
46
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
47
|
-
|
|
48
|
-
import {IPermission, Context} from "@sail/interfaces/IPermission.sol";
|
|
49
|
-
|
|
50
|
-
contract BoundedSwap_UniswapV4_Unichain is IPermission {
|
|
51
|
-
bytes32 private constant DISCRIMINATOR = keccak256("BoundedSwap_UniswapV4_Unichain");
|
|
52
|
-
|
|
53
|
-
address public immutable UNIVERSAL_ROUTER;
|
|
54
|
-
address public immutable FIXED_CURRENCY_IN;
|
|
55
|
-
mapping(address => bool) public isAllowedCurrencyOut;
|
|
56
|
-
uint256 public immutable MAX_AMOUNT_IN;
|
|
57
|
-
uint256 public immutable MIN_BPS;
|
|
58
|
-
|
|
59
|
-
// execute(bytes,bytes[],uint256) — with deadline
|
|
60
|
-
bytes4 private constant SEL_EXECUTE_DEADLINE = 0x3593564c;
|
|
61
|
-
// execute(bytes,bytes[]) — without deadline
|
|
62
|
-
bytes4 private constant SEL_EXECUTE = 0x24856bc3;
|
|
63
|
-
// Universal Router command byte for V4_SWAP
|
|
64
|
-
uint8 private constant CMD_V4_SWAP = 0x10;
|
|
65
|
-
// Bit mask to strip the "allow failure" MSB from a command byte
|
|
66
|
-
uint8 private constant CMD_MASK = 0x3f;
|
|
67
|
-
// V4Router action: SWAP_EXACT_IN_SINGLE
|
|
68
|
-
uint8 private constant ACT_SWAP_EXACT_IN_SINGLE = 0x00;
|
|
69
|
-
|
|
70
|
-
// PoolKey layout must match the deployed V4 PoolManager on Unichain
|
|
71
|
-
struct PoolKey {
|
|
72
|
-
address currency0; // Currency — address type in V4
|
|
73
|
-
address currency1;
|
|
74
|
-
uint24 fee;
|
|
75
|
-
int24 tickSpacing;
|
|
76
|
-
address hooks; // IHooks — address(0) for unhookyed pools
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
struct ExactInputSingleParams {
|
|
80
|
-
PoolKey poolKey;
|
|
81
|
-
bool zeroForOne;
|
|
82
|
-
uint128 amountIn;
|
|
83
|
-
uint128 amountOutMinimum;
|
|
84
|
-
bytes hookData; // not inspected — see limitations header
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
constructor(
|
|
88
|
-
address universalRouter,
|
|
89
|
-
address fixedCurrencyIn,
|
|
90
|
-
address[] memory allowedCurrenciesOut,
|
|
91
|
-
uint256 maxAmountIn,
|
|
92
|
-
uint256 minBps
|
|
93
|
-
) {
|
|
94
|
-
require(minBps <= 10_000, "minBps > 10000");
|
|
95
|
-
UNIVERSAL_ROUTER = universalRouter;
|
|
96
|
-
FIXED_CURRENCY_IN = fixedCurrencyIn;
|
|
97
|
-
MAX_AMOUNT_IN = maxAmountIn;
|
|
98
|
-
MIN_BPS = minBps;
|
|
99
|
-
for (uint256 i = 0; i < allowedCurrenciesOut.length; i++) {
|
|
100
|
-
isAllowedCurrencyOut[allowedCurrenciesOut[i]] = true;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function evaluate(bytes calldata txData, Context calldata ctx) external view returns (bool) {
|
|
105
|
-
if (ctx.target != UNIVERSAL_ROUTER) return false;
|
|
106
|
-
if (ctx.selector != SEL_EXECUTE_DEADLINE && ctx.selector != SEL_EXECUTE) return false;
|
|
107
|
-
if (txData.length < 4) return false;
|
|
108
|
-
|
|
109
|
-
// Decode the execute call. Both overloads start with (bytes commands, bytes[] inputs).
|
|
110
|
-
// abi.decode ignores trailing fields, so decoding as (bytes, bytes[]) works for both.
|
|
111
|
-
(bytes memory commands, bytes[] memory inputs) = abi.decode(txData[4:], (bytes, bytes[]));
|
|
112
|
-
|
|
113
|
-
// Enforce: exactly one command, and it must be V4_SWAP
|
|
114
|
-
if (commands.length != 1) return false;
|
|
115
|
-
if ((uint8(commands[0]) & CMD_MASK) != CMD_V4_SWAP) return false;
|
|
116
|
-
if (inputs.length != 1) return false;
|
|
117
|
-
|
|
118
|
-
// Decode the V4 router call (actions + per-action params)
|
|
119
|
-
(bytes memory v4Actions, bytes[] memory v4Params) =
|
|
120
|
-
abi.decode(inputs[0], (bytes, bytes[]));
|
|
121
|
-
|
|
122
|
-
// Enforce: exactly one V4 action, and it must be SWAP_EXACT_IN_SINGLE
|
|
123
|
-
if (v4Actions.length != 1) return false;
|
|
124
|
-
if (uint8(v4Actions[0]) != ACT_SWAP_EXACT_IN_SINGLE) return false;
|
|
125
|
-
if (v4Params.length != 1) return false;
|
|
126
|
-
|
|
127
|
-
// Decode ExactInputSingleParams from the action param.
|
|
128
|
-
// hookData is a dynamic bytes field — revert here means false (fail closed).
|
|
129
|
-
ExactInputSingleParams memory p = abi.decode(v4Params[0], (ExactInputSingleParams));
|
|
130
|
-
|
|
131
|
-
// Derive tokenIn and tokenOut from the PoolKey and zeroForOne flag.
|
|
132
|
-
// In V4, currency0 < currency1 (sorted by address). zeroForOne = true means
|
|
133
|
-
// trading currency0 for currency1.
|
|
134
|
-
address tokenIn = p.zeroForOne ? p.poolKey.currency0 : p.poolKey.currency1;
|
|
135
|
-
address tokenOut = p.zeroForOne ? p.poolKey.currency1 : p.poolKey.currency0;
|
|
136
|
-
|
|
137
|
-
if (tokenIn != FIXED_CURRENCY_IN) return false;
|
|
138
|
-
if (!isAllowedCurrencyOut[tokenOut]) return false;
|
|
139
|
-
if (p.amountIn > MAX_AMOUNT_IN) return false;
|
|
140
|
-
// Slippage floor: amountOutMinimum ≥ amountIn × MIN_BPS / 10 000.
|
|
141
|
-
// WARNING: compares tokenOut against tokenIn base units. For same-price/same-decimal
|
|
142
|
-
// pairs this maps to a slippage %. For cross-price pairs it is trivially satisfied —
|
|
143
|
-
// real slippage is enforced by the agent off-chain, not by this contract.
|
|
144
|
-
if (p.amountOutMinimum < (uint256(p.amountIn) * MIN_BPS) / 10_000) return false;
|
|
145
|
-
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function discriminator() external pure returns (bytes32) { return DISCRIMINATOR; }
|
|
150
|
-
}
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.26;
|
|
3
|
+
|
|
4
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
+
// Protocol : Uniswap V4
|
|
6
|
+
// Version : Universal Router + PoolManager (V4 singleton)
|
|
7
|
+
// NOTE: V4 is NOT the same as V3. Calldata encoding is completely
|
|
8
|
+
// different — do NOT adapt a V3 permission for V4.
|
|
9
|
+
// Chain : Unichain mainnet
|
|
10
|
+
// Target : Universal Router 0xef740bf23acae26f6492b10de645d6b98dc8eaf3
|
|
11
|
+
// (verify on Uniscan before use)
|
|
12
|
+
//
|
|
13
|
+
// ENFORCES ON-CHAIN (kernel calls evaluate() on every dispatch; false ⇒ dispatch blocked):
|
|
14
|
+
// execute(bytes,bytes[],uint256) selector 0x3593564c / execute(bytes,bytes[]) selector 0x24856bc3
|
|
15
|
+
// • target must be UNIVERSAL_ROUTER
|
|
16
|
+
// • first command byte (masking the allow-failure MSB) must be V4_SWAP (0x10)
|
|
17
|
+
// • exactly one command (single-swap path — disallow multi-hop command strings)
|
|
18
|
+
// • V4 action inside must be SWAP_EXACT_IN_SINGLE (0x00)
|
|
19
|
+
// • tokenIn (from poolKey, derived by zeroForOne) must be FIXED_CURRENCY_IN
|
|
20
|
+
// • tokenOut must be in ALLOWED_CURRENCIES_OUT
|
|
21
|
+
// • amountIn ≤ MAX_AMOUNT_IN
|
|
22
|
+
// • amountOutMinimum ≥ amountIn × MIN_BPS / 10 000 (slippage floor — see caveat below)
|
|
23
|
+
//
|
|
24
|
+
// AGENT-ENFORCED / NOT BOUNDED HERE (off-chain — can change without redeploying this contract):
|
|
25
|
+
// • real (cross-denomination) slippage — see MIN_BPS caveat in evaluate()
|
|
26
|
+
// • swap frequency / cadence
|
|
27
|
+
//
|
|
28
|
+
// DOCUMENTED LIMITATIONS (on-chain, but intentionally not constrained):
|
|
29
|
+
// • hookData is not inspected (hooks can alter swap behavior on-chain; if the
|
|
30
|
+
// pool uses a hook that significantly changes execution, this permission cannot
|
|
31
|
+
// constrain it. Deploy against pools with address(0) hooks or audited hooks only.)
|
|
32
|
+
// • fee tier and tickSpacing within the PoolKey are not constrained here
|
|
33
|
+
// (add pool-key checks if you want to restrict to a specific pool)
|
|
34
|
+
// • The ALL_CURRENCY_PAIR constant (FIXED_CURRENCY_IN, allowedCurrenciesOut) does
|
|
35
|
+
// not constrain which pool is used when multiple pools share the same currency pair
|
|
36
|
+
//
|
|
37
|
+
// VERIFY BEFORE USE:
|
|
38
|
+
// • Confirm Universal Router address on Unichain (shown above; verify on Uniscan).
|
|
39
|
+
// • V4_SWAP command byte = 0x10, SWAP_EXACT_IN_SINGLE action = 0x00 — verify
|
|
40
|
+
// against deployed UniversalRouter and V4Router on Unichain if contract is updated.
|
|
41
|
+
// • PoolKey struct layout (currency0, currency1, fee, tickSpacing, hooks) must
|
|
42
|
+
// match the deployed PoolManager on Unichain. If layout changes, update struct.
|
|
43
|
+
// • hookData is not bounded. Only use with unhookyed pools or audited, bounded hooks.
|
|
44
|
+
// • Calldata revert = false (kernel treats revert as denial) — malformed inputs
|
|
45
|
+
// are safely rejected, but verify with actual calldata samples before deployment.
|
|
46
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
import {IPermission, Context} from "@sail/interfaces/IPermission.sol";
|
|
49
|
+
|
|
50
|
+
contract BoundedSwap_UniswapV4_Unichain is IPermission {
|
|
51
|
+
bytes32 private constant DISCRIMINATOR = keccak256("BoundedSwap_UniswapV4_Unichain");
|
|
52
|
+
|
|
53
|
+
address public immutable UNIVERSAL_ROUTER;
|
|
54
|
+
address public immutable FIXED_CURRENCY_IN;
|
|
55
|
+
mapping(address => bool) public isAllowedCurrencyOut;
|
|
56
|
+
uint256 public immutable MAX_AMOUNT_IN;
|
|
57
|
+
uint256 public immutable MIN_BPS;
|
|
58
|
+
|
|
59
|
+
// execute(bytes,bytes[],uint256) — with deadline
|
|
60
|
+
bytes4 private constant SEL_EXECUTE_DEADLINE = 0x3593564c;
|
|
61
|
+
// execute(bytes,bytes[]) — without deadline
|
|
62
|
+
bytes4 private constant SEL_EXECUTE = 0x24856bc3;
|
|
63
|
+
// Universal Router command byte for V4_SWAP
|
|
64
|
+
uint8 private constant CMD_V4_SWAP = 0x10;
|
|
65
|
+
// Bit mask to strip the "allow failure" MSB from a command byte
|
|
66
|
+
uint8 private constant CMD_MASK = 0x3f;
|
|
67
|
+
// V4Router action: SWAP_EXACT_IN_SINGLE
|
|
68
|
+
uint8 private constant ACT_SWAP_EXACT_IN_SINGLE = 0x00;
|
|
69
|
+
|
|
70
|
+
// PoolKey layout must match the deployed V4 PoolManager on Unichain
|
|
71
|
+
struct PoolKey {
|
|
72
|
+
address currency0; // Currency — address type in V4
|
|
73
|
+
address currency1;
|
|
74
|
+
uint24 fee;
|
|
75
|
+
int24 tickSpacing;
|
|
76
|
+
address hooks; // IHooks — address(0) for unhookyed pools
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
struct ExactInputSingleParams {
|
|
80
|
+
PoolKey poolKey;
|
|
81
|
+
bool zeroForOne;
|
|
82
|
+
uint128 amountIn;
|
|
83
|
+
uint128 amountOutMinimum;
|
|
84
|
+
bytes hookData; // not inspected — see limitations header
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
constructor(
|
|
88
|
+
address universalRouter,
|
|
89
|
+
address fixedCurrencyIn,
|
|
90
|
+
address[] memory allowedCurrenciesOut,
|
|
91
|
+
uint256 maxAmountIn,
|
|
92
|
+
uint256 minBps
|
|
93
|
+
) {
|
|
94
|
+
require(minBps <= 10_000, "minBps > 10000");
|
|
95
|
+
UNIVERSAL_ROUTER = universalRouter;
|
|
96
|
+
FIXED_CURRENCY_IN = fixedCurrencyIn;
|
|
97
|
+
MAX_AMOUNT_IN = maxAmountIn;
|
|
98
|
+
MIN_BPS = minBps;
|
|
99
|
+
for (uint256 i = 0; i < allowedCurrenciesOut.length; i++) {
|
|
100
|
+
isAllowedCurrencyOut[allowedCurrenciesOut[i]] = true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function evaluate(bytes calldata txData, Context calldata ctx) external view returns (bool) {
|
|
105
|
+
if (ctx.target != UNIVERSAL_ROUTER) return false;
|
|
106
|
+
if (ctx.selector != SEL_EXECUTE_DEADLINE && ctx.selector != SEL_EXECUTE) return false;
|
|
107
|
+
if (txData.length < 4) return false;
|
|
108
|
+
|
|
109
|
+
// Decode the execute call. Both overloads start with (bytes commands, bytes[] inputs).
|
|
110
|
+
// abi.decode ignores trailing fields, so decoding as (bytes, bytes[]) works for both.
|
|
111
|
+
(bytes memory commands, bytes[] memory inputs) = abi.decode(txData[4:], (bytes, bytes[]));
|
|
112
|
+
|
|
113
|
+
// Enforce: exactly one command, and it must be V4_SWAP
|
|
114
|
+
if (commands.length != 1) return false;
|
|
115
|
+
if ((uint8(commands[0]) & CMD_MASK) != CMD_V4_SWAP) return false;
|
|
116
|
+
if (inputs.length != 1) return false;
|
|
117
|
+
|
|
118
|
+
// Decode the V4 router call (actions + per-action params)
|
|
119
|
+
(bytes memory v4Actions, bytes[] memory v4Params) =
|
|
120
|
+
abi.decode(inputs[0], (bytes, bytes[]));
|
|
121
|
+
|
|
122
|
+
// Enforce: exactly one V4 action, and it must be SWAP_EXACT_IN_SINGLE
|
|
123
|
+
if (v4Actions.length != 1) return false;
|
|
124
|
+
if (uint8(v4Actions[0]) != ACT_SWAP_EXACT_IN_SINGLE) return false;
|
|
125
|
+
if (v4Params.length != 1) return false;
|
|
126
|
+
|
|
127
|
+
// Decode ExactInputSingleParams from the action param.
|
|
128
|
+
// hookData is a dynamic bytes field — revert here means false (fail closed).
|
|
129
|
+
ExactInputSingleParams memory p = abi.decode(v4Params[0], (ExactInputSingleParams));
|
|
130
|
+
|
|
131
|
+
// Derive tokenIn and tokenOut from the PoolKey and zeroForOne flag.
|
|
132
|
+
// In V4, currency0 < currency1 (sorted by address). zeroForOne = true means
|
|
133
|
+
// trading currency0 for currency1.
|
|
134
|
+
address tokenIn = p.zeroForOne ? p.poolKey.currency0 : p.poolKey.currency1;
|
|
135
|
+
address tokenOut = p.zeroForOne ? p.poolKey.currency1 : p.poolKey.currency0;
|
|
136
|
+
|
|
137
|
+
if (tokenIn != FIXED_CURRENCY_IN) return false;
|
|
138
|
+
if (!isAllowedCurrencyOut[tokenOut]) return false;
|
|
139
|
+
if (p.amountIn > MAX_AMOUNT_IN) return false;
|
|
140
|
+
// Slippage floor: amountOutMinimum ≥ amountIn × MIN_BPS / 10 000.
|
|
141
|
+
// WARNING: compares tokenOut against tokenIn base units. For same-price/same-decimal
|
|
142
|
+
// pairs this maps to a slippage %. For cross-price pairs it is trivially satisfied —
|
|
143
|
+
// real slippage is enforced by the agent off-chain, not by this contract.
|
|
144
|
+
if (p.amountOutMinimum < (uint256(p.amountIn) * MIN_BPS) / 10_000) return false;
|
|
145
|
+
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function discriminator() external pure returns (bytes32) { return DISCRIMINATOR; }
|
|
150
|
+
}
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity 0.8.26;
|
|
3
|
-
|
|
4
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
-
// Protocol : ERC-20
|
|
6
|
-
// Version : Standard ERC-20 (version-agnostic)
|
|
7
|
-
// Chain : Ethereum mainnet (works on any EVM — the most general example)
|
|
8
|
-
//
|
|
9
|
-
// ENFORCES ON-CHAIN (kernel calls evaluate() on every dispatch; false ⇒ dispatch blocked):
|
|
10
|
-
// transfer(address to,uint256 amount) selector 0xa9059cbb
|
|
11
|
-
// • target must be in ALLOWED_TOKENS
|
|
12
|
-
// • recipient (to) must be in ALLOWED_RECIPIENTS
|
|
13
|
-
// • amount ≤ MAX_AMOUNT_PER_TRANSFER
|
|
14
|
-
//
|
|
15
|
-
// AGENT-ENFORCED / NOT BOUNDED HERE (off-chain — can change without redeploying this contract):
|
|
16
|
-
// • transfer frequency / timing
|
|
17
|
-
// • choice of token within ALLOWED_TOKENS
|
|
18
|
-
// • choice of recipient within ALLOWED_RECIPIENTS
|
|
19
|
-
//
|
|
20
|
-
// VERIFY BEFORE USE:
|
|
21
|
-
// • Selector 0xa9059cbb = transfer(address,uint256) — universally standard.
|
|
22
|
-
// • ALLOWED_TOKENS prevents the agent from transferring tokens not in the set.
|
|
23
|
-
// If a protocol uses non-standard transfer methods (e.g. transferFrom or
|
|
24
|
-
// proprietary hooks), add separate selector entries.
|
|
25
|
-
// • MAX_AMOUNT_PER_TRANSFER is denominated in the token's base units.
|
|
26
|
-
// Different tokens have different decimals (USDC = 6, WETH = 18).
|
|
27
|
-
// Set one permission per token if amounts differ across tokens.
|
|
28
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
29
|
-
|
|
30
|
-
import {IPermission, Context} from "@sail/interfaces/IPermission.sol";
|
|
31
|
-
|
|
32
|
-
contract BoundedTransfer_ERC20_Ethereum is IPermission {
|
|
33
|
-
bytes32 private constant DISCRIMINATOR = keccak256("BoundedTransfer_ERC20_Ethereum");
|
|
34
|
-
|
|
35
|
-
mapping(address => bool) public isAllowedToken;
|
|
36
|
-
mapping(address => bool) public isAllowedRecipient;
|
|
37
|
-
uint256 public immutable MAX_AMOUNT_PER_TRANSFER;
|
|
38
|
-
|
|
39
|
-
// transfer(address,uint256)
|
|
40
|
-
bytes4 private constant SEL_TRANSFER = 0xa9059cbb;
|
|
41
|
-
|
|
42
|
-
/// @param allowedTokens ERC-20 contracts the agent may transfer from
|
|
43
|
-
/// @param allowedRecipients Addresses the agent may send to
|
|
44
|
-
/// @param maxAmountPerTransfer Per-call amount cap (in token base units)
|
|
45
|
-
constructor(
|
|
46
|
-
address[] memory allowedTokens,
|
|
47
|
-
address[] memory allowedRecipients,
|
|
48
|
-
uint256 maxAmountPerTransfer
|
|
49
|
-
) {
|
|
50
|
-
MAX_AMOUNT_PER_TRANSFER = maxAmountPerTransfer;
|
|
51
|
-
for (uint256 i = 0; i < allowedTokens.length; i++) {
|
|
52
|
-
isAllowedToken[allowedTokens[i]] = true;
|
|
53
|
-
}
|
|
54
|
-
for (uint256 i = 0; i < allowedRecipients.length; i++) {
|
|
55
|
-
isAllowedRecipient[allowedRecipients[i]] = true;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function evaluate(bytes calldata txData, Context calldata ctx) external view returns (bool) {
|
|
60
|
-
if (!isAllowedToken[ctx.target]) return false;
|
|
61
|
-
if (ctx.selector != SEL_TRANSFER) return false;
|
|
62
|
-
if (txData.length < 4 + 2 * 32) return false;
|
|
63
|
-
|
|
64
|
-
(address to, uint256 amount) = abi.decode(txData[4:], (address, uint256));
|
|
65
|
-
|
|
66
|
-
if (!isAllowedRecipient[to]) return false;
|
|
67
|
-
if (amount > MAX_AMOUNT_PER_TRANSFER) return false;
|
|
68
|
-
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function discriminator() external pure returns (bytes32) { return DISCRIMINATOR; }
|
|
73
|
-
}
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.26;
|
|
3
|
+
|
|
4
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
+
// Protocol : ERC-20
|
|
6
|
+
// Version : Standard ERC-20 (version-agnostic)
|
|
7
|
+
// Chain : Ethereum mainnet (works on any EVM — the most general example)
|
|
8
|
+
//
|
|
9
|
+
// ENFORCES ON-CHAIN (kernel calls evaluate() on every dispatch; false ⇒ dispatch blocked):
|
|
10
|
+
// transfer(address to,uint256 amount) selector 0xa9059cbb
|
|
11
|
+
// • target must be in ALLOWED_TOKENS
|
|
12
|
+
// • recipient (to) must be in ALLOWED_RECIPIENTS
|
|
13
|
+
// • amount ≤ MAX_AMOUNT_PER_TRANSFER
|
|
14
|
+
//
|
|
15
|
+
// AGENT-ENFORCED / NOT BOUNDED HERE (off-chain — can change without redeploying this contract):
|
|
16
|
+
// • transfer frequency / timing
|
|
17
|
+
// • choice of token within ALLOWED_TOKENS
|
|
18
|
+
// • choice of recipient within ALLOWED_RECIPIENTS
|
|
19
|
+
//
|
|
20
|
+
// VERIFY BEFORE USE:
|
|
21
|
+
// • Selector 0xa9059cbb = transfer(address,uint256) — universally standard.
|
|
22
|
+
// • ALLOWED_TOKENS prevents the agent from transferring tokens not in the set.
|
|
23
|
+
// If a protocol uses non-standard transfer methods (e.g. transferFrom or
|
|
24
|
+
// proprietary hooks), add separate selector entries.
|
|
25
|
+
// • MAX_AMOUNT_PER_TRANSFER is denominated in the token's base units.
|
|
26
|
+
// Different tokens have different decimals (USDC = 6, WETH = 18).
|
|
27
|
+
// Set one permission per token if amounts differ across tokens.
|
|
28
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
29
|
+
|
|
30
|
+
import {IPermission, Context} from "@sail/interfaces/IPermission.sol";
|
|
31
|
+
|
|
32
|
+
contract BoundedTransfer_ERC20_Ethereum is IPermission {
|
|
33
|
+
bytes32 private constant DISCRIMINATOR = keccak256("BoundedTransfer_ERC20_Ethereum");
|
|
34
|
+
|
|
35
|
+
mapping(address => bool) public isAllowedToken;
|
|
36
|
+
mapping(address => bool) public isAllowedRecipient;
|
|
37
|
+
uint256 public immutable MAX_AMOUNT_PER_TRANSFER;
|
|
38
|
+
|
|
39
|
+
// transfer(address,uint256)
|
|
40
|
+
bytes4 private constant SEL_TRANSFER = 0xa9059cbb;
|
|
41
|
+
|
|
42
|
+
/// @param allowedTokens ERC-20 contracts the agent may transfer from
|
|
43
|
+
/// @param allowedRecipients Addresses the agent may send to
|
|
44
|
+
/// @param maxAmountPerTransfer Per-call amount cap (in token base units)
|
|
45
|
+
constructor(
|
|
46
|
+
address[] memory allowedTokens,
|
|
47
|
+
address[] memory allowedRecipients,
|
|
48
|
+
uint256 maxAmountPerTransfer
|
|
49
|
+
) {
|
|
50
|
+
MAX_AMOUNT_PER_TRANSFER = maxAmountPerTransfer;
|
|
51
|
+
for (uint256 i = 0; i < allowedTokens.length; i++) {
|
|
52
|
+
isAllowedToken[allowedTokens[i]] = true;
|
|
53
|
+
}
|
|
54
|
+
for (uint256 i = 0; i < allowedRecipients.length; i++) {
|
|
55
|
+
isAllowedRecipient[allowedRecipients[i]] = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function evaluate(bytes calldata txData, Context calldata ctx) external view returns (bool) {
|
|
60
|
+
if (!isAllowedToken[ctx.target]) return false;
|
|
61
|
+
if (ctx.selector != SEL_TRANSFER) return false;
|
|
62
|
+
if (txData.length < 4 + 2 * 32) return false;
|
|
63
|
+
|
|
64
|
+
(address to, uint256 amount) = abi.decode(txData[4:], (address, uint256));
|
|
65
|
+
|
|
66
|
+
if (!isAllowedRecipient[to]) return false;
|
|
67
|
+
if (amount > MAX_AMOUNT_PER_TRANSFER) return false;
|
|
68
|
+
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function discriminator() external pure returns (bytes32) { return DISCRIMINATOR; }
|
|
73
|
+
}
|