@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,30 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {PeerBase} from "./Base.sol";
|
|
5
|
+
import {Data, DataRef, ROUTE_KEY} from "../Blocks.sol";
|
|
6
|
+
using Data for DataRef;
|
|
7
|
+
|
|
8
|
+
string constant NAME = "peerPull";
|
|
9
|
+
|
|
10
|
+
abstract contract PeerPull is PeerBase {
|
|
11
|
+
uint internal immutable peerPullId = peerId(NAME);
|
|
12
|
+
|
|
13
|
+
constructor(string memory route) {
|
|
14
|
+
emit Peer(host, NAME, route, peerPullId);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function peerPull(DataRef memory rawRoute) internal virtual;
|
|
18
|
+
|
|
19
|
+
function peerPull(bytes calldata request) external payable onlyPeer returns (bytes memory) {
|
|
20
|
+
uint q = 0;
|
|
21
|
+
while (q < request.length) {
|
|
22
|
+
(DataRef memory ref, uint next) = Data.from(request, q);
|
|
23
|
+
if (ref.key != ROUTE_KEY) break;
|
|
24
|
+
peerPull(ref);
|
|
25
|
+
q = next;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return done(0, q);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {PeerBase} from "./Base.sol";
|
|
5
|
+
import {Data, DataRef, ROUTE_KEY} from "../Blocks.sol";
|
|
6
|
+
using Data for DataRef;
|
|
7
|
+
|
|
8
|
+
string constant NAME = "peerPush";
|
|
9
|
+
|
|
10
|
+
abstract contract PeerPush is PeerBase {
|
|
11
|
+
uint internal immutable peerPushId = peerId(NAME);
|
|
12
|
+
|
|
13
|
+
constructor(string memory route) {
|
|
14
|
+
emit Peer(host, NAME, route, peerPushId);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function peerPush(DataRef memory rawRoute) internal virtual;
|
|
18
|
+
|
|
19
|
+
function peerPush(bytes calldata request) external payable onlyPeer returns (bytes memory) {
|
|
20
|
+
uint q = 0;
|
|
21
|
+
while (q < request.length) {
|
|
22
|
+
(DataRef memory ref, uint next) = Data.from(request, q);
|
|
23
|
+
if (ref.key != ROUTE_KEY) break;
|
|
24
|
+
peerPush(ref);
|
|
25
|
+
q = next;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return done(0, q);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {AssetAmount, HostAmount, Tx, BlockRef, DataRef, MemRef, Writer, BALANCE_KEY, CUSTODY_KEY, TX_KEY, AMOUNT_KEY, BOUNTY_KEY, RECIPIENT_KEY, NODE_KEY, FUNDING_KEY, ASSET_KEY, ALLOCATION_KEY, STEP_KEY, QUANTITY_KEY} from "../blocks/Schema.sol";
|
|
5
|
+
import {Blocks} from "../blocks/Readers.sol";
|
|
6
|
+
import {Data} from "../blocks/Data.sol";
|
|
7
|
+
import {Mem} from "../blocks/Mem.sol";
|
|
8
|
+
import {InvalidBlock, MalformedBlocks, UnexpectedAsset, UnexpectedHost, UnexpectedMeta, ZeroRecipient, ZeroNode} from "../blocks/Errors.sol";
|
|
9
|
+
import {Writers, BALANCE_BLOCK_LEN, CUSTODY_BLOCK_LEN, TX_BLOCK_LEN} from "../blocks/Writers.sol";
|
|
10
|
+
|
|
11
|
+
using Blocks for BlockRef;
|
|
12
|
+
using Data for DataRef;
|
|
13
|
+
using Writers for Writer;
|
|
14
|
+
using Mem for MemRef;
|
|
15
|
+
|
|
16
|
+
contract TestBlockHelper {
|
|
17
|
+
// ── Writers ──────────────────────────────────────────────────────────────
|
|
18
|
+
|
|
19
|
+
function testBlockHeader(bytes4 key, uint selfLen, uint totalLen) external pure returns (uint) {
|
|
20
|
+
return Writers.toBlockHeader(key, selfLen, totalLen);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function testWriteBalanceBlock(bytes32 asset, bytes32 meta, uint amount) external pure returns (bytes memory) {
|
|
24
|
+
Writer memory w = Writers.alloc(BALANCE_BLOCK_LEN);
|
|
25
|
+
w.appendBalance(asset, meta, amount);
|
|
26
|
+
return w.dst;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function testWriteTwoBalanceBlocks(
|
|
30
|
+
bytes32 a1, bytes32 m1, uint v1,
|
|
31
|
+
bytes32 a2, bytes32 m2, uint v2
|
|
32
|
+
) external pure returns (bytes memory) {
|
|
33
|
+
Writer memory w = Writers.alloc(BALANCE_BLOCK_LEN * 2);
|
|
34
|
+
w.appendBalance(a1, m1, v1);
|
|
35
|
+
w.appendBalance(a2, m2, v2);
|
|
36
|
+
return w.dst;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function testWriteCustodyBlock(uint host_, bytes32 asset, bytes32 meta, uint amount) external pure returns (bytes memory) {
|
|
40
|
+
Writer memory w = Writers.alloc(CUSTODY_BLOCK_LEN);
|
|
41
|
+
w.appendCustody(host_, asset, meta, amount);
|
|
42
|
+
return w.dst;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function testWriteTxBlock(bytes32 from_, bytes32 to_, bytes32 asset, bytes32 meta, uint amount) external pure returns (bytes memory) {
|
|
46
|
+
Writer memory w = Writers.alloc(TX_BLOCK_LEN);
|
|
47
|
+
w.appendTx(Tx({from: from_, to: to_, asset: asset, meta: meta, amount: amount}));
|
|
48
|
+
return w.dst;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function testWriterDone() external pure returns (bytes memory) {
|
|
52
|
+
Writer memory w = Writers.alloc(BALANCE_BLOCK_LEN);
|
|
53
|
+
// Don't write anything — done() should revert
|
|
54
|
+
return Writers.done(w);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function testWriterFinish(bytes32 asset, bytes32 meta, uint amount) external pure returns (bytes memory) {
|
|
58
|
+
Writer memory w = Writers.alloc(BALANCE_BLOCK_LEN * 2);
|
|
59
|
+
w.appendBalance(asset, meta, amount);
|
|
60
|
+
return Writers.finish(w);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ── Blocks (calldata) ────────────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
function testParseBlock(bytes calldata source, uint i)
|
|
66
|
+
external pure returns (bytes4 key, uint bound, uint end)
|
|
67
|
+
{
|
|
68
|
+
BlockRef memory ref = Blocks.from(source, i);
|
|
69
|
+
return (ref.key, ref.bound, ref.end);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function testUnpackAmount(bytes calldata source, uint i)
|
|
73
|
+
external pure returns (bytes32 asset, bytes32 meta, uint amount)
|
|
74
|
+
{
|
|
75
|
+
BlockRef memory ref = Blocks.amountFrom(source, i);
|
|
76
|
+
return ref.unpackAmount(source);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function testUnpackBalance(bytes calldata source, uint i)
|
|
80
|
+
external pure returns (bytes32 asset, bytes32 meta, uint amount)
|
|
81
|
+
{
|
|
82
|
+
BlockRef memory ref = Blocks.balanceFrom(source, i);
|
|
83
|
+
return ref.unpackBalance(source);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function testUnpackCustody(bytes calldata source, uint i)
|
|
87
|
+
external pure returns (uint host_, bytes32 asset, bytes32 meta, uint amount)
|
|
88
|
+
{
|
|
89
|
+
BlockRef memory ref = Blocks.custodyFrom(source, i);
|
|
90
|
+
HostAmount memory v = ref.toCustodyValue(source);
|
|
91
|
+
return (v.host, v.asset, v.meta, v.amount);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function testUnpackRecipient(bytes calldata source, uint i)
|
|
95
|
+
external pure returns (bytes32 account)
|
|
96
|
+
{
|
|
97
|
+
BlockRef memory ref = Blocks.from(source, i);
|
|
98
|
+
return ref.unpackRecipient(source);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function testUnpackNode(bytes calldata source, uint i)
|
|
102
|
+
external pure returns (uint id)
|
|
103
|
+
{
|
|
104
|
+
BlockRef memory ref = Blocks.from(source, i);
|
|
105
|
+
return ref.unpackNode(source);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function testUnpackQuantity(bytes calldata source, uint i)
|
|
109
|
+
external pure returns (uint amount)
|
|
110
|
+
{
|
|
111
|
+
BlockRef memory ref = Blocks.quantityFrom(source, i);
|
|
112
|
+
return ref.unpackQuantity(source);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function testExpectMinimum(bytes calldata source, uint i, bytes32 asset, bytes32 meta)
|
|
116
|
+
external pure returns (uint amount)
|
|
117
|
+
{
|
|
118
|
+
(DataRef memory ref, ) = Data.from(source, i);
|
|
119
|
+
return ref.expectMinimum(asset, meta);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function testExpectAmount(bytes calldata source, uint i, bytes32 asset, bytes32 meta)
|
|
123
|
+
external pure returns (uint amount)
|
|
124
|
+
{
|
|
125
|
+
(DataRef memory ref, ) = Data.from(source, i);
|
|
126
|
+
return ref.expectAmount(asset, meta);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function testExpectBalance(bytes calldata source, uint i, bytes32 asset, bytes32 meta)
|
|
130
|
+
external pure returns (uint amount)
|
|
131
|
+
{
|
|
132
|
+
(DataRef memory ref, ) = Data.from(source, i);
|
|
133
|
+
return ref.expectBalance(asset, meta);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function testExpectMaximum(bytes calldata source, uint i, bytes32 asset, bytes32 meta)
|
|
137
|
+
external pure returns (uint amount)
|
|
138
|
+
{
|
|
139
|
+
(DataRef memory ref, ) = Data.from(source, i);
|
|
140
|
+
return ref.expectMaximum(asset, meta);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function testExpectCustody(bytes calldata source, uint i, uint host_)
|
|
144
|
+
external pure returns (bytes32 asset, bytes32 meta, uint amount)
|
|
145
|
+
{
|
|
146
|
+
(DataRef memory ref, ) = Data.from(source, i);
|
|
147
|
+
AssetAmount memory value = ref.expectCustody(host_);
|
|
148
|
+
return (value.asset, value.meta, value.amount);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function testUnpackFunding(bytes calldata source, uint i)
|
|
152
|
+
external pure returns (uint host_, uint amount)
|
|
153
|
+
{
|
|
154
|
+
BlockRef memory ref = Blocks.from(source, i);
|
|
155
|
+
return ref.unpackFunding(source);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function testUnpackAsset(bytes calldata source, uint i)
|
|
159
|
+
external pure returns (bytes32 asset, bytes32 meta)
|
|
160
|
+
{
|
|
161
|
+
BlockRef memory ref = Blocks.from(source, i);
|
|
162
|
+
return ref.unpackAsset(source);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function testUnpackAllocation(bytes calldata source, uint i)
|
|
166
|
+
external pure returns (uint host_, bytes32 asset, bytes32 meta, uint amount)
|
|
167
|
+
{
|
|
168
|
+
BlockRef memory ref = Blocks.from(source, i);
|
|
169
|
+
HostAmount memory v = ref.toAllocationValue(source);
|
|
170
|
+
return (v.host, v.asset, v.meta, v.amount);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function testToTxValue(bytes calldata source, uint i)
|
|
174
|
+
external pure returns (bytes32 from_, bytes32 to_, bytes32 asset, bytes32 meta, uint amount)
|
|
175
|
+
{
|
|
176
|
+
BlockRef memory ref = Blocks.from(source, i);
|
|
177
|
+
Tx memory t = ref.toTxValue(source);
|
|
178
|
+
return (t.from, t.to, t.asset, t.meta, t.amount);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function testCountBlocks(bytes calldata source, uint i, bytes4 key)
|
|
182
|
+
external pure returns (uint count, uint next)
|
|
183
|
+
{
|
|
184
|
+
return Blocks.count(source, i, key);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function testResolveRecipient(bytes calldata source, uint i, uint limit, bytes32 backup)
|
|
188
|
+
external pure returns (bytes32)
|
|
189
|
+
{
|
|
190
|
+
return Blocks.resolveRecipient(source, i, limit, backup);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function testResolveNode(bytes calldata source, uint i, uint limit, uint backup)
|
|
194
|
+
external pure returns (uint)
|
|
195
|
+
{
|
|
196
|
+
return Blocks.resolveNode(source, i, limit, backup);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function testCreate32(bytes4 key, bytes32 value) external pure returns (bytes memory) {
|
|
200
|
+
return Blocks.create32(key, value);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function testCreate64(bytes4 key, bytes32 a, bytes32 b) external pure returns (bytes memory) {
|
|
204
|
+
return Blocks.create64(key, a, b);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function testCreate96(bytes4 key, bytes32 a, bytes32 b, bytes32 c) external pure returns (bytes memory) {
|
|
208
|
+
return Blocks.create96(key, a, b, c);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function testCreate128(bytes4 key, bytes32 a, bytes32 b, bytes32 c, bytes32 d) external pure returns (bytes memory) {
|
|
212
|
+
return Blocks.create128(key, a, b, c, d);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function testToBounty(uint amount, bytes32 relayer) external pure returns (bytes memory) {
|
|
216
|
+
return Blocks.toBountyBlock(amount, relayer);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function testToCustody(uint host_, bytes32 asset, bytes32 meta, uint amount) external pure returns (bytes memory) {
|
|
220
|
+
return Blocks.toCustodyBlock(host_, asset, meta, amount);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ── Mem (memory) ─────────────────────────────────────────────────────────
|
|
224
|
+
|
|
225
|
+
function testMemParseBalance(bytes memory source, uint i)
|
|
226
|
+
external pure returns (bytes32 asset, bytes32 meta, uint amount)
|
|
227
|
+
{
|
|
228
|
+
MemRef memory ref = Mem.from(source, i);
|
|
229
|
+
return ref.unpackBalance(source);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function testMemParseCustody(bytes memory source, uint i)
|
|
233
|
+
external pure returns (HostAmount memory value)
|
|
234
|
+
{
|
|
235
|
+
MemRef memory ref = Mem.from(source, i);
|
|
236
|
+
return ref.toCustodyValue(source);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function testMemSlice(bytes memory source, uint start, uint end_)
|
|
240
|
+
external pure returns (bytes memory)
|
|
241
|
+
{
|
|
242
|
+
return Mem.slice(source, start, end_);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function testMemCount(bytes memory source, uint i, bytes4 key)
|
|
246
|
+
external pure returns (uint count, uint next)
|
|
247
|
+
{
|
|
248
|
+
return Mem.count(source, i, key);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function testAllocBalancesFromCount(bytes calldata source, uint i, bytes4 sourceKey)
|
|
252
|
+
external pure returns (uint count, uint next)
|
|
253
|
+
{
|
|
254
|
+
return Blocks.count(source, i, sourceKey);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {Host} from "../core/Host.sol";
|
|
5
|
+
import {BorrowAgainstCustodyToBalance} from "../commands/Borrow.sol";
|
|
6
|
+
import {AssetAmount, HostAmount, DataRef} from "../blocks/Schema.sol";
|
|
7
|
+
import {Data} from "../blocks/Data.sol";
|
|
8
|
+
import {toHostId} from "../utils/Ids.sol";
|
|
9
|
+
|
|
10
|
+
using Data for DataRef;
|
|
11
|
+
|
|
12
|
+
contract TestBorrowHost is Host, BorrowAgainstCustodyToBalance {
|
|
13
|
+
event BorrowCalled(bytes32 account, bytes32 asset, bytes32 meta, uint amount, bytes routeData);
|
|
14
|
+
|
|
15
|
+
bytes32 public returnAsset;
|
|
16
|
+
bytes32 public returnMeta;
|
|
17
|
+
uint public returnAmount;
|
|
18
|
+
|
|
19
|
+
constructor(address cmdr) Host(address(0), 1, "test") BorrowAgainstCustodyToBalance("") {
|
|
20
|
+
if (cmdr != address(0)) access(toHostId(cmdr), true);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function setReturn(bytes32 asset, bytes32 meta, uint amount) external {
|
|
24
|
+
returnAsset = asset;
|
|
25
|
+
returnMeta = meta;
|
|
26
|
+
returnAmount = amount;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function borrowAgainstCustodyToBalance(
|
|
30
|
+
bytes32 account,
|
|
31
|
+
HostAmount memory custody,
|
|
32
|
+
DataRef memory rawRoute
|
|
33
|
+
) internal override returns (AssetAmount memory) {
|
|
34
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
35
|
+
emit BorrowCalled(account, custody.asset, custody.meta, custody.amount, routeData);
|
|
36
|
+
return AssetAmount({asset: returnAsset, meta: returnMeta, amount: returnAmount});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getBorrowId() external view returns (uint) {
|
|
40
|
+
return borrowAgainstCustodyToBalanceId;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getAdminAccount() external view returns (bytes32) {
|
|
44
|
+
return adminAccount;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {Host} from "../core/Host.sol";
|
|
5
|
+
import {Burn} from "../commands/Burn.sol";
|
|
6
|
+
import {toHostId} from "../utils/Ids.sol";
|
|
7
|
+
|
|
8
|
+
contract TestBurnHost is Host, Burn {
|
|
9
|
+
event BurnCalled(bytes32 account, bytes32 asset, bytes32 meta, uint amount);
|
|
10
|
+
|
|
11
|
+
constructor(address cmdr)
|
|
12
|
+
Host(address(0), 1, "test")
|
|
13
|
+
Burn("")
|
|
14
|
+
{
|
|
15
|
+
if (cmdr != address(0)) access(toHostId(cmdr), true);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function burn(bytes32 account, bytes32 asset, bytes32 meta, uint amount)
|
|
19
|
+
internal override
|
|
20
|
+
returns (uint)
|
|
21
|
+
{
|
|
22
|
+
emit BurnCalled(account, asset, meta, amount);
|
|
23
|
+
return amount;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function getBurnId() external view returns (uint) { return burnId; }
|
|
27
|
+
function getAdminAccount() external view returns (bytes32) { return adminAccount; }
|
|
28
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {Host} from "../core/Host.sol";
|
|
5
|
+
import {Create} from "../commands/Create.sol";
|
|
6
|
+
import {DataRef} from "../blocks/Schema.sol";
|
|
7
|
+
import {toHostId} from "../utils/Ids.sol";
|
|
8
|
+
|
|
9
|
+
contract TestCreateHost is Host, Create {
|
|
10
|
+
event CreateCalled(bytes32 account, bytes routeData);
|
|
11
|
+
|
|
12
|
+
constructor(address cmdr)
|
|
13
|
+
Host(address(0), 1, "test")
|
|
14
|
+
Create("")
|
|
15
|
+
{
|
|
16
|
+
if (cmdr != address(0)) access(toHostId(cmdr), true);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function create(bytes32 account, DataRef memory rawRoute) internal override {
|
|
20
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
21
|
+
emit CreateCalled(account, routeData);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getCreateId() external view returns (uint) { return createId; }
|
|
25
|
+
function getAdminAccount() external view returns (bytes32) { return adminAccount; }
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {ECDSA} from "../utils/ECDSA.sol";
|
|
5
|
+
|
|
6
|
+
contract TestECDSA {
|
|
7
|
+
using ECDSA for bytes32;
|
|
8
|
+
|
|
9
|
+
function testToEthSignedMessageHash(bytes32 hash) external pure returns (bytes32) {
|
|
10
|
+
return hash.toEthSignedMessageHash();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function testTryRecoverCalldata(bytes32 hash, bytes calldata signature) external pure returns (address) {
|
|
14
|
+
return hash.tryRecoverCalldata(signature);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {Host} from "../core/Host.sol";
|
|
5
|
+
import {Deposit} from "../commands/Deposit.sol";
|
|
6
|
+
import {Withdraw} from "../commands/Withdraw.sol";
|
|
7
|
+
import {Transfer} from "../commands/Transfer.sol";
|
|
8
|
+
import {CreditBalanceToAccount} from "../commands/CreditTo.sol";
|
|
9
|
+
import {DebitAccountToBalance} from "../commands/DebitFrom.sol";
|
|
10
|
+
import {Settle} from "../commands/Settle.sol";
|
|
11
|
+
import {Fund} from "../commands/Fund.sol";
|
|
12
|
+
import {Provision} from "../commands/Provision.sol";
|
|
13
|
+
import {Pipe} from "../commands/Pipe.sol";
|
|
14
|
+
import {AllowAssets} from "../commands/admin/AllowAssets.sol";
|
|
15
|
+
import {DenyAssets} from "../commands/admin/DenyAssets.sol";
|
|
16
|
+
import {Destroy} from "../commands/admin/Destroy.sol";
|
|
17
|
+
import {Init} from "../commands/admin/Init.sol";
|
|
18
|
+
import {Allocate} from "../commands/admin/Allocate.sol";
|
|
19
|
+
import {DataRef, Tx, Writer} from "../blocks/Schema.sol";
|
|
20
|
+
import {Writers} from "../blocks/Writers.sol";
|
|
21
|
+
|
|
22
|
+
using Writers for Writer;
|
|
23
|
+
|
|
24
|
+
contract TestHost is
|
|
25
|
+
Host,
|
|
26
|
+
Deposit,
|
|
27
|
+
Withdraw,
|
|
28
|
+
Transfer,
|
|
29
|
+
CreditBalanceToAccount,
|
|
30
|
+
DebitAccountToBalance,
|
|
31
|
+
Settle,
|
|
32
|
+
Fund,
|
|
33
|
+
Provision,
|
|
34
|
+
Pipe,
|
|
35
|
+
Init,
|
|
36
|
+
Destroy,
|
|
37
|
+
AllowAssets,
|
|
38
|
+
DenyAssets,
|
|
39
|
+
Allocate
|
|
40
|
+
{
|
|
41
|
+
event DepositCalled(bytes32 account, bytes32 asset, bytes32 meta, uint amount);
|
|
42
|
+
event WithdrawCalled(bytes32 account, bytes32 asset, bytes32 meta, uint amount);
|
|
43
|
+
event TransferCalled(bytes32 from_, bytes32 to_, bytes32 asset, bytes32 meta, uint amount);
|
|
44
|
+
event CreditToCalled(bytes32 account, bytes32 asset, bytes32 meta, uint amount, uint returned);
|
|
45
|
+
event DebitFromCalled(bytes32 account, bytes32 asset, bytes32 meta, uint amount, uint returned);
|
|
46
|
+
event SettleCalled(bytes32 from_, bytes32 to_, bytes32 asset, bytes32 meta, uint amount);
|
|
47
|
+
event FundCalled(uint host_, bytes32 account, bytes32 asset, bytes32 meta, uint amount);
|
|
48
|
+
event ProvisionCalled(uint host_, bytes32 account, bytes32 asset, bytes32 meta, uint amount);
|
|
49
|
+
event InitCalled(bytes routeData);
|
|
50
|
+
event DestroyCalled(bytes routeData);
|
|
51
|
+
event AllowAssetCalled(bytes32 asset, bytes32 meta);
|
|
52
|
+
event DenyAssetCalled(bytes32 asset, bytes32 meta);
|
|
53
|
+
event AllocateCalled(uint host_, bytes32 asset, bytes32 meta, uint amount);
|
|
54
|
+
event StepDispatched(uint target, uint stepIndex, uint value);
|
|
55
|
+
|
|
56
|
+
uint public stepCount;
|
|
57
|
+
|
|
58
|
+
constructor(address fastish) Host(fastish, 1, "test") Deposit() Provision(10_000) Init("") Destroy("") {}
|
|
59
|
+
|
|
60
|
+
function deposit(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal override {
|
|
61
|
+
emit DepositCalled(account, asset, meta, amount);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function withdraw(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal override {
|
|
65
|
+
emit WithdrawCalled(account, asset, meta, amount);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function transfer(bytes32 from_, bytes32 to_, bytes32 asset, bytes32 meta, uint amount) internal override {
|
|
69
|
+
emit TransferCalled(from_, to_, asset, meta, amount);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function creditAccount(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal override {
|
|
73
|
+
emit CreditToCalled(account, asset, meta, amount, amount);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function debitAccount(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal override {
|
|
77
|
+
emit DebitFromCalled(account, asset, meta, amount, amount);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function settle(Tx memory value) internal override {
|
|
81
|
+
emit SettleCalled(value.from, value.to, value.asset, value.meta, value.amount);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function fund(uint host_, bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal override {
|
|
85
|
+
emit FundCalled(host_, account, asset, meta, amount);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function provision(
|
|
89
|
+
bytes32 account,
|
|
90
|
+
uint host_,
|
|
91
|
+
bytes32 asset,
|
|
92
|
+
bytes32 meta,
|
|
93
|
+
uint amount,
|
|
94
|
+
Writer memory out
|
|
95
|
+
) internal override {
|
|
96
|
+
emit ProvisionCalled(host_, account, asset, meta, amount);
|
|
97
|
+
out.appendCustody(host_, asset, meta, amount);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function init(DataRef memory rawRoute) internal override {
|
|
101
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
102
|
+
emit InitCalled(routeData);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function destroy(DataRef memory rawRoute) internal override {
|
|
106
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
107
|
+
emit DestroyCalled(routeData);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function allowAsset(bytes32 asset, bytes32 meta) internal override returns (bool) {
|
|
111
|
+
emit AllowAssetCalled(asset, meta);
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function denyAsset(bytes32 asset, bytes32 meta) internal override returns (bool) {
|
|
116
|
+
emit DenyAssetCalled(asset, meta);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function allocate(uint host_, bytes32 asset, bytes32 meta, uint amount) internal override {
|
|
121
|
+
emit AllocateCalled(host_, asset, meta, amount);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function dispatchStep(
|
|
125
|
+
uint target,
|
|
126
|
+
bytes32,
|
|
127
|
+
bytes memory state,
|
|
128
|
+
bytes calldata,
|
|
129
|
+
uint value
|
|
130
|
+
) internal override returns (bytes memory) {
|
|
131
|
+
emit StepDispatched(target, stepCount++, value);
|
|
132
|
+
return state;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Expose internal host/admin IDs for tests
|
|
136
|
+
function getDepositId() external view returns (uint) {
|
|
137
|
+
return depositId;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function getWithdrawId() external view returns (uint) {
|
|
141
|
+
return withdrawId;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function getTransferId() external view returns (uint) {
|
|
145
|
+
return transferId;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function getCreditBalanceToAccountId() external view returns (uint) {
|
|
149
|
+
return creditBalanceToAccountId;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function getDebitAccountToBalanceId() external view returns (uint) {
|
|
153
|
+
return debitAccountToBalanceId;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function getSettleId() external view returns (uint) {
|
|
157
|
+
return settleId;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function getFundId() external view returns (uint) {
|
|
161
|
+
return fundId;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function getProvisionId() external view returns (uint) {
|
|
165
|
+
return provisionId;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function getPipeId() external view returns (uint) {
|
|
169
|
+
return pipeId;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function getInitId() external view returns (uint) {
|
|
173
|
+
return initId;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function getDestroyId() external view returns (uint) {
|
|
177
|
+
return destroyId;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function getAuthorizeId() external view returns (uint) {
|
|
181
|
+
return authorizeId;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function getUnauthorizeId() external view returns (uint) {
|
|
185
|
+
return unauthorizeId;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function getRelocateId() external view returns (uint) {
|
|
189
|
+
return relocateId;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function getAllowAssetsId() external view returns (uint) {
|
|
193
|
+
return allowAssetsId;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function getDenyAssetsId() external view returns (uint) {
|
|
197
|
+
return denyAssetsId;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function getAllocateId() external view returns (uint) {
|
|
201
|
+
return allocateId;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function getAdminAccount() external view returns (bytes32) {
|
|
205
|
+
return adminAccount;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function getCommander() external view returns (address) {
|
|
209
|
+
return commander;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function isAuthorized(uint node) external view returns (bool) {
|
|
213
|
+
return authorized[node];
|
|
214
|
+
}
|
|
215
|
+
}
|