@rootzero/contracts 0.5.0 → 0.5.1
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/docs/GETTING_STARTED.md +286 -0
- package/package.json +17 -33
- package/contracts/test/TestBorrowHost.sol +0 -72
- package/contracts/test/TestBurnHost.sol +0 -31
- package/contracts/test/TestCreateHost.sol +0 -40
- package/contracts/test/TestCursorHelper.sol +0 -191
- package/contracts/test/TestDiscovery.sol +0 -9
- package/contracts/test/TestECDSA.sol +0 -19
- package/contracts/test/TestHost.sol +0 -218
- package/contracts/test/TestLiquidityHost.sol +0 -167
- package/contracts/test/TestMintHost.sol +0 -50
- package/contracts/test/TestOperation.sol +0 -21
- package/contracts/test/TestPeerHost.sol +0 -57
- package/contracts/test/TestReclaimHost.sol +0 -55
- package/contracts/test/TestRejectEther.sol +0 -11
- package/contracts/test/TestRemoveHost.sol +0 -40
- package/contracts/test/TestSupplyHost.sol +0 -25
- package/contracts/test/TestSwapHost.sol +0 -67
- package/contracts/test/TestUtils.sol +0 -184
- package/contracts/test/TestValidator.sol +0 -13
- /package/{contracts/Commands.sol → Commands.sol} +0 -0
- /package/{contracts/Core.sol → Core.sol} +0 -0
- /package/{contracts/Cursors.sol → Cursors.sol} +0 -0
- /package/{contracts/Events.sol → Events.sol} +0 -0
- /package/{contracts/Utils.sol → Utils.sol} +0 -0
- /package/{contracts/blocks → blocks}/Cursors.sol +0 -0
- /package/{contracts/blocks → blocks}/Keys.sol +0 -0
- /package/{contracts/blocks → blocks}/Schema.sol +0 -0
- /package/{contracts/blocks → blocks}/Writers.sol +0 -0
- /package/{contracts/commands → commands}/Base.sol +0 -0
- /package/{contracts/commands → commands}/Borrow.sol +0 -0
- /package/{contracts/commands → commands}/Burn.sol +0 -0
- /package/{contracts/commands → commands}/Create.sol +0 -0
- /package/{contracts/commands → commands}/Credit.sol +0 -0
- /package/{contracts/commands → commands}/Debit.sol +0 -0
- /package/{contracts/commands → commands}/Deposit.sol +0 -0
- /package/{contracts/commands → commands}/Liquidate.sol +0 -0
- /package/{contracts/commands → commands}/Liquidity.sol +0 -0
- /package/{contracts/commands → commands}/Mint.sol +0 -0
- /package/{contracts/commands → commands}/Pipe.sol +0 -0
- /package/{contracts/commands → commands}/Provision.sol +0 -0
- /package/{contracts/commands → commands}/Reclaim.sol +0 -0
- /package/{contracts/commands → commands}/Redeem.sol +0 -0
- /package/{contracts/commands → commands}/Remove.sol +0 -0
- /package/{contracts/commands → commands}/Repay.sol +0 -0
- /package/{contracts/commands → commands}/Settle.sol +0 -0
- /package/{contracts/commands → commands}/Stake.sol +0 -0
- /package/{contracts/commands → commands}/Supply.sol +0 -0
- /package/{contracts/commands → commands}/Swap.sol +0 -0
- /package/{contracts/commands → commands}/Transfer.sol +0 -0
- /package/{contracts/commands → commands}/Unstake.sol +0 -0
- /package/{contracts/commands → commands}/Withdraw.sol +0 -0
- /package/{contracts/commands → commands}/admin/Allocate.sol +0 -0
- /package/{contracts/commands → commands}/admin/AllowAssets.sol +0 -0
- /package/{contracts/commands → commands}/admin/Authorize.sol +0 -0
- /package/{contracts/commands → commands}/admin/DenyAssets.sol +0 -0
- /package/{contracts/commands → commands}/admin/Destroy.sol +0 -0
- /package/{contracts/commands → commands}/admin/Init.sol +0 -0
- /package/{contracts/commands → commands}/admin/Relocate.sol +0 -0
- /package/{contracts/commands → commands}/admin/Unauthorize.sol +0 -0
- /package/{contracts/core → core}/Access.sol +0 -0
- /package/{contracts/core → core}/Balances.sol +0 -0
- /package/{contracts/core → core}/Host.sol +0 -0
- /package/{contracts/core → core}/Operation.sol +0 -0
- /package/{contracts/core → core}/Validator.sol +0 -0
- /package/{contracts/events → events}/Access.sol +0 -0
- /package/{contracts/events → events}/Asset.sol +0 -0
- /package/{contracts/events → events}/Balance.sol +0 -0
- /package/{contracts/events → events}/Collateral.sol +0 -0
- /package/{contracts/events → events}/Command.sol +0 -0
- /package/{contracts/events → events}/Debt.sol +0 -0
- /package/{contracts/events → events}/Deposit.sol +0 -0
- /package/{contracts/events → events}/Emitter.sol +0 -0
- /package/{contracts/events → events}/Governed.sol +0 -0
- /package/{contracts/events → events}/HostAnnounced.sol +0 -0
- /package/{contracts/events → events}/Listing.sol +0 -0
- /package/{contracts/events → events}/Peer.sol +0 -0
- /package/{contracts/events → events}/Quote.sol +0 -0
- /package/{contracts/events → events}/RootZero.sol +0 -0
- /package/{contracts/events → events}/Withdraw.sol +0 -0
- /package/{contracts/interfaces → interfaces}/IHostDiscovery.sol +0 -0
- /package/{contracts/peer → peer}/AllowAssets.sol +0 -0
- /package/{contracts/peer → peer}/Base.sol +0 -0
- /package/{contracts/peer → peer}/DenyAssets.sol +0 -0
- /package/{contracts/peer → peer}/Pull.sol +0 -0
- /package/{contracts/peer → peer}/Push.sol +0 -0
- /package/{contracts/peer → peer}/Settle.sol +0 -0
- /package/{contracts/utils → utils}/Accounts.sol +0 -0
- /package/{contracts/utils → utils}/Assets.sol +0 -0
- /package/{contracts/utils → utils}/ECDSA.sol +0 -0
- /package/{contracts/utils → utils}/Ids.sol +0 -0
- /package/{contracts/utils → utils}/Layout.sol +0 -0
- /package/{contracts/utils → utils}/State.sol +0 -0
- /package/{contracts/utils → utils}/Utils.sol +0 -0
- /package/{contracts/utils → utils}/Value.sol +0 -0
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { Host } from "../core/Host.sol";
|
|
5
|
-
import { SwapExactBalanceToBalance } from "../commands/Swap.sol";
|
|
6
|
-
import { AssetAmount, Cur, Cursors, Cursors, Keys } from "../Cursors.sol";
|
|
7
|
-
|
|
8
|
-
using Cursors for Cur;
|
|
9
|
-
|
|
10
|
-
contract TestSwapHost is Host, SwapExactBalanceToBalance {
|
|
11
|
-
event SwapMapped(bytes32 account, bytes32 asset, bytes32 meta, uint amount, bytes inputData);
|
|
12
|
-
event SwapMinimum(bytes32 asset, bytes32 meta, uint amount);
|
|
13
|
-
|
|
14
|
-
constructor(address rootzero)
|
|
15
|
-
Host(rootzero, 1, "test")
|
|
16
|
-
SwapExactBalanceToBalance("route(bytes data)")
|
|
17
|
-
{}
|
|
18
|
-
|
|
19
|
-
function swapExactBalanceToBalance(
|
|
20
|
-
bytes32 account,
|
|
21
|
-
AssetAmount memory balance,
|
|
22
|
-
Cur memory request
|
|
23
|
-
) internal override returns (AssetAmount memory out) {
|
|
24
|
-
if (request.i == request.len) revert Cursors.InvalidBlock();
|
|
25
|
-
|
|
26
|
-
Cur memory input = request;
|
|
27
|
-
(bytes4 key, uint len) = request.peek(request.i);
|
|
28
|
-
if (key == Keys.Bundle) input = request.bundle();
|
|
29
|
-
|
|
30
|
-
bytes calldata inputData;
|
|
31
|
-
(key, len) = input.peek(input.i);
|
|
32
|
-
if (key == Keys.Route) {
|
|
33
|
-
inputData = input.unpackRoute();
|
|
34
|
-
} else {
|
|
35
|
-
uint next = input.i + 8 + len;
|
|
36
|
-
inputData = msg.data[input.offset + input.i:input.offset + next];
|
|
37
|
-
input.i = next;
|
|
38
|
-
}
|
|
39
|
-
emit SwapMapped(account, balance.asset, balance.meta, balance.amount, inputData);
|
|
40
|
-
|
|
41
|
-
if (input.i < input.len) {
|
|
42
|
-
(key, ) = input.peek(input.i);
|
|
43
|
-
}
|
|
44
|
-
if (input.i < input.len && key == Keys.Minimum) {
|
|
45
|
-
(bytes32 minAsset, bytes32 minMeta, uint minAmount) = input.unpackMinimum();
|
|
46
|
-
emit SwapMinimum(minAsset, minMeta, minAmount);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return AssetAmount({
|
|
50
|
-
asset: balance.asset,
|
|
51
|
-
meta: bytes32(inputData.length),
|
|
52
|
-
amount: balance.amount + inputData.length
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function getSwapExactInAsset32Id() external view returns (uint) {
|
|
57
|
-
return swapExactBalanceToBalanceId;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function getAdminAccount() external view returns (bytes32) {
|
|
61
|
-
return adminAccount;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { Accounts } from "../utils/Accounts.sol";
|
|
5
|
-
import { Amounts, Assets } from "../utils/Assets.sol";
|
|
6
|
-
import { Ids, Selectors } from "../utils/Ids.sol";
|
|
7
|
-
import { addrOr, applyBps, beforeBps, bytes32ToString, isFamily, isLocal, isLocalFamily, matchesBase, toLocalBase, toUnspecifiedBase, max8, max16, max32, max64, max128, max160 } from "../utils/Utils.sol";
|
|
8
|
-
import { Values } from "../utils/Value.sol";
|
|
9
|
-
|
|
10
|
-
contract TestUtils {
|
|
11
|
-
function testAddrOr(address addr, address or_) external pure returns (address) {
|
|
12
|
-
return addrOr(addr, or_);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function testToAdminAccount(address addr) external view returns (bytes32) {
|
|
16
|
-
return Accounts.toAdmin(addr);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function testToUserAccount(address addr) external pure returns (bytes32) {
|
|
20
|
-
return Accounts.toUser(addr);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function testAccountEvmAddr(bytes32 account) external pure returns (address) {
|
|
24
|
-
return Accounts.addrEvm(account);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function testIsAdminAccount(bytes32 account) external pure returns (bool) {
|
|
28
|
-
return Accounts.isAdmin(account);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function testIsKeccakAccount(bytes32 account) external pure returns (bool) {
|
|
32
|
-
return Accounts.isKeccak(account);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function testToKeccakAccount(bytes calldata raw) external pure returns (bytes32) {
|
|
36
|
-
return Accounts.toKeccak(raw);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function testMatchesKeccakAccount(bytes32 account, bytes calldata raw) external pure returns (bool) {
|
|
40
|
-
return Accounts.matchesKeccak(account, raw);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function testToValueAsset() external view returns (bytes32) {
|
|
44
|
-
return Assets.toValue();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function testToErc20Asset(address addr) external view returns (bytes32) {
|
|
48
|
-
return Assets.toErc20(addr);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function testToErc721Asset(address addr) external view returns (bytes32) {
|
|
52
|
-
return Assets.toErc721(addr);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function testIsAsset32(bytes32 asset) external pure returns (bool) {
|
|
56
|
-
return Assets.is32(asset);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function testResolveAmount(uint available, uint min, uint max) external pure returns (uint) {
|
|
60
|
-
return Amounts.resolve(available, min, max);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function testEnsureAmount(uint amount) external pure returns (uint) {
|
|
64
|
-
return Amounts.ensure(amount);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function testEnsureAmountRange(uint amount, uint min, uint max) external pure returns (uint) {
|
|
68
|
-
return Amounts.ensure(amount, min, max);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function testAssetKey(bytes32 asset, bytes32 meta) external pure returns (bytes32) {
|
|
72
|
-
return Assets.key(asset, meta);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function testLocalErc20Addr(bytes32 asset) external view returns (address) {
|
|
76
|
-
return Assets.erc20Addr(asset);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function testLocalErc721Issuer(bytes32 asset) external view returns (address) {
|
|
80
|
-
return Assets.erc721Issuer(asset);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function testToHostId(address addr) external view returns (uint) {
|
|
84
|
-
return Ids.toHost(addr);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function testToCommandId(bytes32 name, address addr) external view returns (uint) {
|
|
88
|
-
return Ids.toCommand(Selectors.command(bytes32ToString(name)), addr);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function testToCommandSelector(bytes32 name) external pure returns (bytes4) {
|
|
92
|
-
return Selectors.command(bytes32ToString(name));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function testIsHost(uint id) external pure returns (bool) {
|
|
96
|
-
return Ids.isHost(id);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function testIsCommand(uint id) external pure returns (bool) {
|
|
100
|
-
return Ids.isCommand(id);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function testLocalNodeAddr(uint node) external view returns (address) {
|
|
104
|
-
return Ids.nodeAddr(node);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function testLocalHostAddr(uint host) external view returns (address) {
|
|
108
|
-
return Ids.hostAddr(host);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function testEnsureHost(uint id, address addr) external view returns (uint) {
|
|
112
|
-
return Ids.host(id, addr);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function testEnsureCommand(uint id) external pure returns (uint) {
|
|
116
|
-
return Ids.command(id);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function testApplyBps(uint amount, uint16 bps) external pure returns (uint) {
|
|
120
|
-
return applyBps(amount, bps);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function testBeforeBps(uint amount, uint16 bps) external pure returns (uint) {
|
|
124
|
-
return beforeBps(amount, bps);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function testIsFamily(uint value, uint24 family) external pure returns (bool) {
|
|
128
|
-
return isFamily(value, family);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function testIsLocal(uint value) external view returns (bool) {
|
|
132
|
-
return isLocal(value);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function testMatchesBase(bytes32 value, uint base) external pure returns (bool) {
|
|
136
|
-
return matchesBase(value, base);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function testToLocalBase(uint32 prefix) external view returns (uint) {
|
|
140
|
-
return toLocalBase(prefix);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function testMsgValue() external payable returns (uint) {
|
|
144
|
-
Values.Budget memory budget = Values.fromMsg();
|
|
145
|
-
return budget.remaining;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function testUseValue(uint amount, uint remaining) external pure returns (uint spent, uint remainingAfter) {
|
|
149
|
-
Values.Budget memory budget = Values.Budget({remaining: remaining});
|
|
150
|
-
spent = Values.use(budget, amount);
|
|
151
|
-
remainingAfter = budget.remaining;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function testBytes32ToString(bytes32 value) external pure returns (string memory) {
|
|
155
|
-
return bytes32ToString(value);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function testMax8(uint value) external pure returns (uint) {
|
|
159
|
-
return max8(value);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function testMax16(uint value) external pure returns (uint) {
|
|
163
|
-
return max16(value);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function testMax32(uint value) external pure returns (uint) {
|
|
167
|
-
return max32(value);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function testMax64(uint value) external pure returns (uint) {
|
|
171
|
-
return max64(value);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function testMax128(uint value) external pure returns (uint) {
|
|
175
|
-
return max128(value);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function testMax160(uint value) external pure returns (uint) {
|
|
179
|
-
return max160(value);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { Validator } from "../core/Validator.sol";
|
|
5
|
-
|
|
6
|
-
contract TestValidator is Validator {
|
|
7
|
-
function testVerify(bytes32 hash, uint192 nonce, bytes calldata proof) external returns (address) {
|
|
8
|
-
return verify(hash, nonce, proof);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|