@fastish/contracts 0.1.0
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/LICENSE +648 -0
- package/README.md +134 -0
- package/contracts/Blocks.sol +73 -0
- package/contracts/Commands.sol +47 -0
- package/contracts/Core.sol +10 -0
- package/contracts/Events.sol +18 -0
- package/contracts/Schema.sol +57 -0
- package/contracts/Utils.sol +105 -0
- package/contracts/blocks/Data.sol +646 -0
- package/contracts/blocks/Errors.sol +10 -0
- package/contracts/blocks/Mem.sol +122 -0
- package/contracts/blocks/Readers.sol +938 -0
- package/contracts/blocks/Schema.sol +148 -0
- package/contracts/blocks/Writers.sol +187 -0
- package/contracts/combinators/AmountToBalance.sol +26 -0
- package/contracts/combinators/AmountToCustody.sol +37 -0
- package/contracts/combinators/CustodyToBalance.sol +27 -0
- package/contracts/combinators/EachRoute.sol +19 -0
- package/contracts/combinators/MapBalance.sol +26 -0
- package/contracts/combinators/MapCustody.sol +26 -0
- package/contracts/combinators/RouteToBalance.sol +27 -0
- package/contracts/commands/Base.sol +39 -0
- package/contracts/commands/Borrow.sol +86 -0
- package/contracts/commands/Burn.sol +32 -0
- package/contracts/commands/Create.sol +31 -0
- package/contracts/commands/CreditTo.sol +36 -0
- package/contracts/commands/DebitFrom.sol +44 -0
- package/contracts/commands/Deposit.sol +46 -0
- package/contracts/commands/Fund.sol +37 -0
- package/contracts/commands/Liquidate.sol +93 -0
- package/contracts/commands/Liquidity.sol +171 -0
- package/contracts/commands/Mint.sol +41 -0
- package/contracts/commands/Pipe.sol +54 -0
- package/contracts/commands/Provision.sol +48 -0
- package/contracts/commands/Reclaim.sol +46 -0
- package/contracts/commands/Redeem.sol +93 -0
- package/contracts/commands/Remove.sol +31 -0
- package/contracts/commands/Repay.sol +93 -0
- package/contracts/commands/Settle.sol +32 -0
- package/contracts/commands/Stake.sol +114 -0
- package/contracts/commands/Supply.sol +32 -0
- package/contracts/commands/Swap.sol +86 -0
- package/contracts/commands/Transfer.sol +41 -0
- package/contracts/commands/Unstake.sol +49 -0
- package/contracts/commands/Withdraw.sol +37 -0
- package/contracts/commands/admin/Allocate.sol +33 -0
- package/contracts/commands/admin/AllowAssets.sol +34 -0
- package/contracts/commands/admin/Authorize.sol +32 -0
- package/contracts/commands/admin/DenyAssets.sol +34 -0
- package/contracts/commands/admin/Destroy.sol +26 -0
- package/contracts/commands/admin/Init.sol +26 -0
- package/contracts/commands/admin/Relocate.sol +32 -0
- package/contracts/commands/admin/Unauthorize.sol +32 -0
- package/contracts/core/Access.sol +49 -0
- package/contracts/core/Balances.sol +9 -0
- package/contracts/core/Host.sol +25 -0
- package/contracts/core/Operation.sol +32 -0
- package/contracts/core/Validator.sol +31 -0
- package/contracts/events/Access.sol +14 -0
- package/contracts/events/Asset.sol +14 -0
- package/contracts/events/Balance.sol +14 -0
- package/contracts/events/Collateral.sol +15 -0
- package/contracts/events/Command.sol +14 -0
- package/contracts/events/Debt.sol +15 -0
- package/contracts/events/Deposit.sol +14 -0
- package/contracts/events/Emitter.sol +7 -0
- package/contracts/events/Fastish.sol +14 -0
- package/contracts/events/Governed.sol +14 -0
- package/contracts/events/HostAnnounced.sol +14 -0
- package/contracts/events/Listing.sol +14 -0
- package/contracts/events/Peer.sol +14 -0
- package/contracts/events/Quote.sol +14 -0
- package/contracts/events/Withdraw.sol +14 -0
- package/contracts/interfaces/IHostDiscovery.sol +6 -0
- package/contracts/peer/AllowAssets.sol +31 -0
- package/contracts/peer/Base.sol +19 -0
- package/contracts/peer/DenyAssets.sol +31 -0
- package/contracts/peer/Pull.sol +30 -0
- package/contracts/peer/Push.sol +30 -0
- package/contracts/test/TestBlockHelper.sol +256 -0
- package/contracts/test/TestBorrowHost.sol +46 -0
- package/contracts/test/TestBurnHost.sol +28 -0
- package/contracts/test/TestCreateHost.sol +26 -0
- package/contracts/test/TestDiscovery.sol +6 -0
- package/contracts/test/TestECDSA.sol +16 -0
- package/contracts/test/TestHost.sol +215 -0
- package/contracts/test/TestLiquidityHost.sol +149 -0
- package/contracts/test/TestMintHost.sol +40 -0
- package/contracts/test/TestPeerHost.sol +34 -0
- package/contracts/test/TestReclaimHost.sol +47 -0
- package/contracts/test/TestRejectEther.sol +8 -0
- package/contracts/test/TestRemoveHost.sol +26 -0
- package/contracts/test/TestSwapHost.sol +45 -0
- package/contracts/test/TestUtils.sol +180 -0
- package/contracts/test/TestValidator.sol +10 -0
- package/contracts/utils/Accounts.sol +42 -0
- package/contracts/utils/Assets.sol +71 -0
- package/contracts/utils/Channels.sol +9 -0
- package/contracts/utils/ECDSA.sol +36 -0
- package/contracts/utils/Ids.sol +75 -0
- package/contracts/utils/Layout.sol +20 -0
- package/contracts/utils/Strings.sol +16 -0
- package/contracts/utils/Utils.sol +117 -0
- package/contracts/utils/Value.sol +18 -0
- package/package.json +29 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {CommandBase, CommandContext} from "../Base.sol";
|
|
5
|
+
import {SETUP} from "../../utils/Channels.sol";
|
|
6
|
+
import {BlockRef, NODE, NODE_KEY} from "../../blocks/Schema.sol";
|
|
7
|
+
import {Blocks} from "../../blocks/Readers.sol";
|
|
8
|
+
using Blocks for BlockRef;
|
|
9
|
+
|
|
10
|
+
string constant NAME = "authorize";
|
|
11
|
+
|
|
12
|
+
abstract contract Authorize is CommandBase {
|
|
13
|
+
uint internal immutable authorizeId = commandId(NAME);
|
|
14
|
+
|
|
15
|
+
constructor() {
|
|
16
|
+
emit Command(host, NAME, NODE, authorizeId, SETUP, SETUP);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function authorize(
|
|
20
|
+
CommandContext calldata c
|
|
21
|
+
) external payable onlyAdmin(c.account) onlyCommand(authorizeId, c.target) returns (bytes memory) {
|
|
22
|
+
uint i = 0;
|
|
23
|
+
while (i < c.request.length) {
|
|
24
|
+
BlockRef memory ref = Blocks.from(c.request, i);
|
|
25
|
+
if (ref.key != NODE_KEY) break;
|
|
26
|
+
uint node = ref.unpackNode(c.request);
|
|
27
|
+
access(node, true);
|
|
28
|
+
i = ref.end;
|
|
29
|
+
}
|
|
30
|
+
return done(0, i);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {CommandBase, CommandContext} from "../Base.sol";
|
|
5
|
+
import {SETUP} from "../../utils/Channels.sol";
|
|
6
|
+
import {ASSET, ASSET_KEY, BlockRef} from "../../blocks/Schema.sol";
|
|
7
|
+
import {Blocks} from "../../blocks/Readers.sol";
|
|
8
|
+
using Blocks for BlockRef;
|
|
9
|
+
|
|
10
|
+
string constant NAME = "denyAssets";
|
|
11
|
+
|
|
12
|
+
abstract contract DenyAssets is CommandBase {
|
|
13
|
+
uint internal immutable denyAssetsId = commandId(NAME);
|
|
14
|
+
|
|
15
|
+
constructor() {
|
|
16
|
+
emit Command(host, NAME, ASSET, denyAssetsId, SETUP, SETUP);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function denyAsset(bytes32 asset, bytes32 meta) internal virtual returns (bool);
|
|
20
|
+
|
|
21
|
+
function denyAssets(
|
|
22
|
+
CommandContext calldata c
|
|
23
|
+
) external payable onlyAdmin(c.account) onlyCommand(denyAssetsId, c.target) returns (bytes memory) {
|
|
24
|
+
uint i = 0;
|
|
25
|
+
while (i < c.request.length) {
|
|
26
|
+
BlockRef memory ref = Blocks.from(c.request, i);
|
|
27
|
+
if (ref.key != ASSET_KEY) break;
|
|
28
|
+
(bytes32 asset, bytes32 meta) = ref.unpackAsset(c.request);
|
|
29
|
+
denyAsset(asset, meta);
|
|
30
|
+
i = ref.end;
|
|
31
|
+
}
|
|
32
|
+
return done(0, i);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {CommandBase, CommandContext} from "../Base.sol";
|
|
5
|
+
import {SETUP} from "../../utils/Channels.sol";
|
|
6
|
+
import {Data, DataRef} from "../../Blocks.sol";
|
|
7
|
+
|
|
8
|
+
string constant NAME = "destroy";
|
|
9
|
+
|
|
10
|
+
abstract contract Destroy is CommandBase {
|
|
11
|
+
uint internal immutable destroyId = commandId(NAME);
|
|
12
|
+
|
|
13
|
+
constructor(string memory route) {
|
|
14
|
+
emit Command(host, NAME, route, destroyId, SETUP, SETUP);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function destroy(DataRef memory rawRoute) internal virtual;
|
|
18
|
+
|
|
19
|
+
function destroy(
|
|
20
|
+
CommandContext calldata c
|
|
21
|
+
) external payable onlyAdmin(c.account) onlyCommand(destroyId, c.target) returns (bytes memory) {
|
|
22
|
+
(DataRef memory route, uint q) = Data.routeFrom(c.request, 0);
|
|
23
|
+
destroy(route);
|
|
24
|
+
return done(0, q);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {CommandBase, CommandContext} from "../Base.sol";
|
|
5
|
+
import {SETUP} from "../../utils/Channels.sol";
|
|
6
|
+
import {Data, DataRef} from "../../Blocks.sol";
|
|
7
|
+
|
|
8
|
+
string constant NAME = "init";
|
|
9
|
+
|
|
10
|
+
abstract contract Init is CommandBase {
|
|
11
|
+
uint internal immutable initId = commandId(NAME);
|
|
12
|
+
|
|
13
|
+
constructor(string memory route) {
|
|
14
|
+
emit Command(host, NAME, route, initId, SETUP, SETUP);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function init(DataRef memory rawRoute) internal virtual;
|
|
18
|
+
|
|
19
|
+
function init(
|
|
20
|
+
CommandContext calldata c
|
|
21
|
+
) external payable onlyAdmin(c.account) onlyCommand(initId, c.target) returns (bytes memory) {
|
|
22
|
+
(DataRef memory route, uint q) = Data.routeFrom(c.request, 0);
|
|
23
|
+
init(route);
|
|
24
|
+
return done(0, q);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {CommandBase, CommandContext} from "../Base.sol";
|
|
5
|
+
import {SETUP} from "../../utils/Channels.sol";
|
|
6
|
+
import {BlockRef, FUNDING, FUNDING_KEY} from "../../blocks/Schema.sol";
|
|
7
|
+
import {Blocks} from "../../blocks/Readers.sol";
|
|
8
|
+
using Blocks for BlockRef;
|
|
9
|
+
|
|
10
|
+
string constant NAME = "relocate";
|
|
11
|
+
|
|
12
|
+
abstract contract Relocate is CommandBase {
|
|
13
|
+
uint internal immutable relocateId = commandId(NAME);
|
|
14
|
+
|
|
15
|
+
constructor() {
|
|
16
|
+
emit Command(host, NAME, FUNDING, relocateId, SETUP, SETUP);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function relocate(
|
|
20
|
+
CommandContext calldata c
|
|
21
|
+
) external payable onlyAdmin(c.account) onlyCommand(relocateId, c.target) returns (bytes memory) {
|
|
22
|
+
uint i = 0;
|
|
23
|
+
while (i < c.request.length) {
|
|
24
|
+
BlockRef memory ref = Blocks.from(c.request, i);
|
|
25
|
+
if (ref.key != FUNDING_KEY) break;
|
|
26
|
+
(uint host, uint amount) = ref.unpackFunding(c.request);
|
|
27
|
+
callTo(host, amount, "");
|
|
28
|
+
i = ref.end;
|
|
29
|
+
}
|
|
30
|
+
return done(0, i);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {CommandBase, CommandContext} from "../Base.sol";
|
|
5
|
+
import {SETUP} from "../../utils/Channels.sol";
|
|
6
|
+
import {BlockRef, NODE, NODE_KEY} from "../../blocks/Schema.sol";
|
|
7
|
+
import {Blocks} from "../../blocks/Readers.sol";
|
|
8
|
+
using Blocks for BlockRef;
|
|
9
|
+
|
|
10
|
+
string constant NAME = "unauthorize";
|
|
11
|
+
|
|
12
|
+
abstract contract Unauthorize is CommandBase {
|
|
13
|
+
uint internal immutable unauthorizeId = commandId(NAME);
|
|
14
|
+
|
|
15
|
+
constructor() {
|
|
16
|
+
emit Command(host, NAME, NODE, unauthorizeId, SETUP, SETUP);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function unauthorize(
|
|
20
|
+
CommandContext calldata c
|
|
21
|
+
) external payable onlyAdmin(c.account) onlyCommand(unauthorizeId, c.target) returns (bytes memory) {
|
|
22
|
+
uint i = 0;
|
|
23
|
+
while (i < c.request.length) {
|
|
24
|
+
BlockRef memory ref = Blocks.from(c.request, i);
|
|
25
|
+
if (ref.key != NODE_KEY) break;
|
|
26
|
+
uint node = ref.unpackNode(c.request);
|
|
27
|
+
access(node, false);
|
|
28
|
+
i = ref.end;
|
|
29
|
+
}
|
|
30
|
+
return done(0, i);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {AccessEvent} from "../events/Access.sol";
|
|
5
|
+
import {addrOr, toAdminAccount} from "../utils/Accounts.sol";
|
|
6
|
+
import {toHostId} from "../utils/Ids.sol";
|
|
7
|
+
|
|
8
|
+
abstract contract AccessControl is AccessEvent {
|
|
9
|
+
address internal immutable commander;
|
|
10
|
+
bytes32 internal immutable adminAccount;
|
|
11
|
+
uint public immutable host;
|
|
12
|
+
|
|
13
|
+
mapping(uint => bool) internal authorized;
|
|
14
|
+
|
|
15
|
+
error UnauthorizedNode(uint node);
|
|
16
|
+
error UnauthorizedCaller(address addr);
|
|
17
|
+
|
|
18
|
+
constructor(address cmdr) {
|
|
19
|
+
commander = addrOr(cmdr, address(this));
|
|
20
|
+
adminAccount = toAdminAccount(commander);
|
|
21
|
+
host = toHostId(address(this));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// @dev inbound auth is host-based.
|
|
25
|
+
function access(uint node, bool allow) internal {
|
|
26
|
+
authorized[node] = allow;
|
|
27
|
+
emit Access(host, node, allow);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isTrusted(address caller) internal view returns (bool) {
|
|
31
|
+
return caller == commander || caller == address(this) || authorized[toHostId(caller)];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function enforceCaller(address caller) internal view returns (address) {
|
|
35
|
+
if (caller == address(0) || !isTrusted(caller)) {
|
|
36
|
+
revert UnauthorizedCaller(caller);
|
|
37
|
+
}
|
|
38
|
+
return caller;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// @dev Outbound trust check: accepts any authorized node id (host or COMMAND).
|
|
42
|
+
// Inbound caller auth is host-only via `enforceCaller(msg.sender)`.
|
|
43
|
+
function ensureTrusted(uint node) internal view returns (uint) {
|
|
44
|
+
if (node == 0 || !authorized[node]) {
|
|
45
|
+
revert UnauthorizedNode(node);
|
|
46
|
+
}
|
|
47
|
+
return node;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {BalanceEvent} from "../events/Balance.sol";
|
|
5
|
+
|
|
6
|
+
abstract contract Balances is BalanceEvent {
|
|
7
|
+
mapping(bytes32 account => mapping(bytes32 assetRef => uint amount))
|
|
8
|
+
internal balances;
|
|
9
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {AccessControl} from "./Access.sol";
|
|
5
|
+
import {Authorize} from "../commands/admin/Authorize.sol";
|
|
6
|
+
import {Unauthorize} from "../commands/admin/Unauthorize.sol";
|
|
7
|
+
import {Relocate} from "../commands/admin/Relocate.sol";
|
|
8
|
+
import {HostAnnouncedEvent} from "../events/HostAnnounced.sol";
|
|
9
|
+
import {IHostDiscovery} from "../interfaces/IHostDiscovery.sol";
|
|
10
|
+
import {ensureHost} from "../utils/Ids.sol";
|
|
11
|
+
|
|
12
|
+
abstract contract HostDiscovery is HostAnnouncedEvent, IHostDiscovery {
|
|
13
|
+
function announceHost(uint id, uint blocknum, uint16 version, string calldata namespace) external {
|
|
14
|
+
emit HostAnnounced(ensureHost(id, msg.sender), blocknum, version, namespace);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
abstract contract Host is Authorize, Unauthorize, Relocate {
|
|
19
|
+
constructor(address fastish, uint8 version, string memory namespace) AccessControl(fastish) {
|
|
20
|
+
if (fastish == address(0) || fastish == address(this) || fastish.code.length == 0) return;
|
|
21
|
+
IHostDiscovery(fastish).announceHost(host, block.number, version, namespace);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
receive() external payable {}
|
|
25
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {AccessControl} from "./Access.sol";
|
|
5
|
+
import {toValueAsset} from "../utils/Assets.sol";
|
|
6
|
+
import {localNodeAddr} from "../utils/Ids.sol";
|
|
7
|
+
|
|
8
|
+
error NoOperation();
|
|
9
|
+
error FailedCall(address addr, uint node, bytes4 selector, bytes err);
|
|
10
|
+
|
|
11
|
+
abstract contract OperationBase is AccessControl {
|
|
12
|
+
bytes32 public immutable valueAsset = toValueAsset();
|
|
13
|
+
|
|
14
|
+
function done(uint start, uint end) internal pure returns (bytes memory) {
|
|
15
|
+
if (end <= start) revert NoOperation();
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function done(bytes memory state, uint start, uint end) internal pure returns (bytes memory) {
|
|
20
|
+
if (end <= start) revert NoOperation();
|
|
21
|
+
return state;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function callTo(uint node, uint value, bytes memory data) internal returns (bytes memory out) {
|
|
25
|
+
bool success;
|
|
26
|
+
address addr = localNodeAddr(ensureTrusted(node));
|
|
27
|
+
(success, out) = payable(addr).call{value: value}(data);
|
|
28
|
+
if (!success) {
|
|
29
|
+
revert FailedCall(addr, node, bytes4(data), out);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {ECDSA} from "../utils/ECDSA.sol";
|
|
5
|
+
|
|
6
|
+
abstract contract Validator {
|
|
7
|
+
using ECDSA for bytes32;
|
|
8
|
+
|
|
9
|
+
error InvalidProof();
|
|
10
|
+
error InvalidSigner();
|
|
11
|
+
error InvalidNonce();
|
|
12
|
+
|
|
13
|
+
mapping(address account => mapping(uint192 key => uint64)) internal nonces;
|
|
14
|
+
|
|
15
|
+
function recover(bytes32 hash, bytes calldata sig) private pure returns (address) {
|
|
16
|
+
return hash.toEthSignedMessageHash().tryRecoverCalldata(sig);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// @dev proof is (bytes20 signer, bytes65 sig)
|
|
20
|
+
function verify(bytes32 hash, uint192 nonce, bytes calldata proof) internal returns (address) {
|
|
21
|
+
if (proof.length != 85) revert InvalidProof();
|
|
22
|
+
|
|
23
|
+
address account = address(bytes20(proof[0:20]));
|
|
24
|
+
address signer = recover(hash, proof[20:]);
|
|
25
|
+
|
|
26
|
+
if (account == address(0) || signer != account) revert InvalidSigner();
|
|
27
|
+
if (nonces[account][nonce]++ != 0) revert InvalidNonce();
|
|
28
|
+
|
|
29
|
+
return account;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
string constant ABI = "event Access(uint indexed host, uint node, bool trusted)";
|
|
7
|
+
|
|
8
|
+
abstract contract AccessEvent is EventEmitter {
|
|
9
|
+
event Access(uint indexed host, uint node, bool trusted);
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
emit EventAbi(ABI);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
string constant ABI = "event Asset(uint indexed host, bytes32 name, bytes4 prefix, string format)";
|
|
7
|
+
|
|
8
|
+
abstract contract AssetEvent is EventEmitter {
|
|
9
|
+
event Asset(uint indexed host, bytes32 name, bytes4 prefix, string format);
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
emit EventAbi(ABI);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
string constant ABI = "event Balance(bytes32 indexed account, bytes32 asset, bytes32 meta, uint balance, int change, uint access)";
|
|
7
|
+
|
|
8
|
+
abstract contract BalanceEvent is EventEmitter {
|
|
9
|
+
event Balance(bytes32 indexed account, bytes32 asset, bytes32 meta, uint balance, int change, uint access);
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
emit EventAbi(ABI);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
string constant ABI = "event Collateral(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint access)";
|
|
7
|
+
|
|
8
|
+
// Query should be provided for the access command to get the exact colleteral.
|
|
9
|
+
abstract contract CollateralEvent is EventEmitter {
|
|
10
|
+
event Collateral(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint access);
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
emit EventAbi(ABI);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
string constant ABI = "event Command(uint indexed host, string name, string schema, uint cid, uint8 stateIn, uint8 stateOut)";
|
|
7
|
+
|
|
8
|
+
abstract contract CommandEvent is EventEmitter {
|
|
9
|
+
event Command(uint indexed host, string name, string schema, uint cid, uint8 stateIn, uint8 stateOut);
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
emit EventAbi(ABI);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
string constant ABI = "event Debt(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint mode, uint access)";
|
|
7
|
+
|
|
8
|
+
// Query should be provided for the access command to get the exact debt.
|
|
9
|
+
abstract contract DebtEvent is EventEmitter {
|
|
10
|
+
event Debt(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint mode, uint access);
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
emit EventAbi(ABI);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
string constant ABI = "event Deposit(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint cid)";
|
|
7
|
+
|
|
8
|
+
abstract contract DepositEvent is EventEmitter {
|
|
9
|
+
event Deposit(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint cid);
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
emit EventAbi(ABI);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
string constant ABI = "event Fastish(uint indexed host, bytes32 account, uint deadline, uint value)";
|
|
7
|
+
|
|
8
|
+
abstract contract FastishEvent is EventEmitter {
|
|
9
|
+
event Fastish(uint indexed host, bytes32 account, uint deadline, uint value);
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
emit EventAbi(ABI);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
string constant ABI = "event Governed(uint indexed host, uint deadline, uint value)";
|
|
7
|
+
|
|
8
|
+
abstract contract GovernedEvent is EventEmitter {
|
|
9
|
+
event Governed(uint indexed host, uint deadline, uint value);
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
emit EventAbi(ABI);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
string constant ABI = "event HostAnnounced(uint indexed host, uint blocknum, uint16 version, string namespace)";
|
|
7
|
+
|
|
8
|
+
abstract contract HostAnnouncedEvent is EventEmitter {
|
|
9
|
+
event HostAnnounced(uint indexed host, uint blocknum, uint16 version, string namespace);
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
emit EventAbi(ABI);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
string constant ABI = "event Listing(uint indexed host, bytes32 asset, bytes32 meta, bool active, bool created)";
|
|
7
|
+
|
|
8
|
+
abstract contract ListingEvent is EventEmitter {
|
|
9
|
+
event Listing(uint indexed host, bytes32 asset, bytes32 meta, bool active, bool created);
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
emit EventAbi(ABI);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
string constant ABI = "event Peer(uint indexed host, string name, string schema, uint pid)";
|
|
7
|
+
|
|
8
|
+
abstract contract PeerEvent is EventEmitter {
|
|
9
|
+
event Peer(uint indexed host, string name, string schema, uint pid);
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
emit EventAbi(ABI);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
string constant ABI = "event Quote(uint indexed host, uint cid, string schema)";
|
|
7
|
+
|
|
8
|
+
abstract contract QuoteEvent is EventEmitter {
|
|
9
|
+
event Quote(uint indexed host, uint cid, string schema);
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
emit EventAbi(ABI);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
string constant ABI = "event Withdrawal(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint cid)";
|
|
7
|
+
|
|
8
|
+
abstract contract WithdrawalEvent is EventEmitter {
|
|
9
|
+
event Withdrawal(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint cid);
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
emit EventAbi(ABI);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {PeerBase} from "./Base.sol";
|
|
5
|
+
import {ASSET, ASSET_KEY, BlockRef} from "../blocks/Schema.sol";
|
|
6
|
+
import {Blocks} from "../blocks/Readers.sol";
|
|
7
|
+
using Blocks for BlockRef;
|
|
8
|
+
|
|
9
|
+
string constant NAME = "peerAllowAssets";
|
|
10
|
+
|
|
11
|
+
abstract contract PeerAllowAssets is PeerBase {
|
|
12
|
+
uint internal immutable peerAllowAssetsId = peerId(NAME);
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
emit Peer(host, NAME, ASSET, peerAllowAssetsId);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function peerAllowAsset(bytes32 asset, bytes32 meta) internal virtual returns (bool);
|
|
19
|
+
|
|
20
|
+
function peerAllowAssets(bytes calldata request) external payable onlyPeer returns (bytes memory) {
|
|
21
|
+
uint q = 0;
|
|
22
|
+
while (q < request.length) {
|
|
23
|
+
BlockRef memory ref = Blocks.from(request, q);
|
|
24
|
+
if (ref.key != ASSET_KEY) break;
|
|
25
|
+
(bytes32 asset, bytes32 meta) = ref.unpackAsset(request);
|
|
26
|
+
peerAllowAsset(asset, meta);
|
|
27
|
+
q = ref.end;
|
|
28
|
+
}
|
|
29
|
+
return done(0, q);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {OperationBase} from "../core/Operation.sol";
|
|
5
|
+
import {PeerEvent} from "../events/Peer.sol";
|
|
6
|
+
import {toPeerId, toPeerSelector} from "../utils/Ids.sol";
|
|
7
|
+
|
|
8
|
+
error NoResponse();
|
|
9
|
+
|
|
10
|
+
abstract contract PeerBase is OperationBase, PeerEvent {
|
|
11
|
+
modifier onlyPeer() {
|
|
12
|
+
enforceCaller(msg.sender);
|
|
13
|
+
_;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function peerId(string memory name) internal view returns (uint) {
|
|
17
|
+
return toPeerId(toPeerSelector(name), address(this));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {PeerBase} from "./Base.sol";
|
|
5
|
+
import {ASSET, ASSET_KEY, BlockRef} from "../blocks/Schema.sol";
|
|
6
|
+
import {Blocks} from "../blocks/Readers.sol";
|
|
7
|
+
using Blocks for BlockRef;
|
|
8
|
+
|
|
9
|
+
string constant NAME = "peerDenyAssets";
|
|
10
|
+
|
|
11
|
+
abstract contract PeerDenyAssets is PeerBase {
|
|
12
|
+
uint internal immutable peerDenyAssetsId = peerId(NAME);
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
emit Peer(host, NAME, ASSET, peerDenyAssetsId);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function peerDenyAsset(bytes32 asset, bytes32 meta) internal virtual returns (bool);
|
|
19
|
+
|
|
20
|
+
function peerDenyAssets(bytes calldata request) external payable onlyPeer returns (bytes memory) {
|
|
21
|
+
uint q = 0;
|
|
22
|
+
while (q < request.length) {
|
|
23
|
+
BlockRef memory ref = Blocks.from(request, q);
|
|
24
|
+
if (ref.key != ASSET_KEY) break;
|
|
25
|
+
(bytes32 asset, bytes32 meta) = ref.unpackAsset(request);
|
|
26
|
+
peerDenyAsset(asset, meta);
|
|
27
|
+
q = ref.end;
|
|
28
|
+
}
|
|
29
|
+
return done(0, q);
|
|
30
|
+
}
|
|
31
|
+
}
|