@rootzero/contracts 0.2.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 +135 -0
- package/contracts/Blocks.sol +9 -0
- package/contracts/Commands.sol +41 -0
- package/contracts/Core.sol +10 -0
- package/contracts/Events.sol +18 -0
- package/contracts/Utils.sol +12 -0
- package/contracts/blocks/Blocks.sol +818 -0
- package/contracts/blocks/Keys.sol +24 -0
- package/contracts/blocks/Mem.sol +129 -0
- package/contracts/blocks/Schema.sol +105 -0
- package/contracts/blocks/Writers.sol +209 -0
- package/contracts/combinators/AmountToBalance.sol +25 -0
- package/contracts/combinators/AmountToCustody.sol +36 -0
- package/contracts/combinators/CustodyToBalance.sol +25 -0
- package/contracts/combinators/EachRoute.sol +18 -0
- package/contracts/combinators/MapBalance.sol +25 -0
- package/contracts/combinators/MapCustody.sol +25 -0
- package/contracts/combinators/RouteToBalance.sol +27 -0
- package/contracts/commands/Base.sol +40 -0
- package/contracts/commands/Borrow.sol +89 -0
- package/contracts/commands/Burn.sol +33 -0
- package/contracts/commands/Create.sol +32 -0
- package/contracts/commands/Credit.sol +36 -0
- package/contracts/commands/Debit.sol +46 -0
- package/contracts/commands/Deposit.sol +45 -0
- package/contracts/commands/Liquidate.sol +101 -0
- package/contracts/commands/Liquidity.sol +179 -0
- package/contracts/commands/Mint.sol +42 -0
- package/contracts/commands/Pipe.sol +55 -0
- package/contracts/commands/Provision.sol +73 -0
- package/contracts/commands/Reclaim.sol +48 -0
- package/contracts/commands/Redeem.sol +101 -0
- package/contracts/commands/Remove.sol +32 -0
- package/contracts/commands/Repay.sol +101 -0
- package/contracts/commands/Settle.sol +32 -0
- package/contracts/commands/Stake.sol +121 -0
- package/contracts/commands/Supply.sol +33 -0
- package/contracts/commands/Swap.sol +88 -0
- package/contracts/commands/Transfer.sol +44 -0
- package/contracts/commands/Unstake.sol +49 -0
- package/contracts/commands/Withdraw.sol +37 -0
- package/contracts/commands/admin/Allocate.sol +32 -0
- package/contracts/commands/admin/AllowAssets.sol +34 -0
- package/contracts/commands/admin/Authorize.sol +30 -0
- package/contracts/commands/admin/DenyAssets.sol +34 -0
- package/contracts/commands/admin/Destroy.sol +27 -0
- package/contracts/commands/admin/Init.sol +26 -0
- package/contracts/commands/admin/Relocate.sol +30 -0
- package/contracts/commands/admin/Unauthorize.sol +30 -0
- package/contracts/core/Access.sol +50 -0
- package/contracts/core/Balances.sol +23 -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/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/RootZero.sol +14 -0
- package/contracts/events/Withdraw.sol +14 -0
- package/contracts/interfaces/IHostDiscovery.sol +6 -0
- package/contracts/peer/AllowAssets.sol +30 -0
- package/contracts/peer/Base.sol +17 -0
- package/contracts/peer/DenyAssets.sol +30 -0
- package/contracts/peer/Pull.sol +30 -0
- package/contracts/peer/Push.sol +30 -0
- package/contracts/test/TestBlockHelper.sol +261 -0
- package/contracts/test/TestBorrowHost.sol +47 -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 +199 -0
- package/contracts/test/TestLiquidityHost.sol +145 -0
- package/contracts/test/TestMintHost.sol +40 -0
- package/contracts/test/TestPeerHost.sol +34 -0
- package/contracts/test/TestReclaimHost.sol +48 -0
- package/contracts/test/TestRejectEther.sol +8 -0
- package/contracts/test/TestRemoveHost.sol +26 -0
- package/contracts/test/TestSwapHost.sol +44 -0
- package/contracts/test/TestUtils.sol +169 -0
- package/contracts/test/TestValidator.sol +10 -0
- package/contracts/utils/Accounts.sol +40 -0
- package/contracts/utils/Assets.sol +76 -0
- package/contracts/utils/Channels.sol +11 -0
- package/contracts/utils/ECDSA.sol +36 -0
- package/contracts/utils/Ids.sol +75 -0
- package/contracts/utils/Layout.sol +22 -0
- package/contracts/utils/Utils.sol +126 -0
- package/contracts/utils/Value.sol +20 -0
- package/package.json +33 -0
|
@@ -0,0 +1,199 @@
|
|
|
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 { CreditAccount } from "../commands/Credit.sol";
|
|
9
|
+
import { DebitAccount } from "../commands/Debit.sol";
|
|
10
|
+
import { Settle } from "../commands/Settle.sol";
|
|
11
|
+
import { Provision, ProvisionFromBalance } from "../commands/Provision.sol";
|
|
12
|
+
import { Pipe } from "../commands/Pipe.sol";
|
|
13
|
+
import { AllowAssets } from "../commands/admin/AllowAssets.sol";
|
|
14
|
+
import { DenyAssets } from "../commands/admin/DenyAssets.sol";
|
|
15
|
+
import { Destroy } from "../commands/admin/Destroy.sol";
|
|
16
|
+
import { Init } from "../commands/admin/Init.sol";
|
|
17
|
+
import { Allocate } from "../commands/admin/Allocate.sol";
|
|
18
|
+
import { Tx } from "../blocks/Schema.sol";
|
|
19
|
+
import { Block } from "../Blocks.sol";
|
|
20
|
+
|
|
21
|
+
contract TestHost is
|
|
22
|
+
Host,
|
|
23
|
+
Deposit,
|
|
24
|
+
Withdraw,
|
|
25
|
+
Transfer,
|
|
26
|
+
CreditAccount,
|
|
27
|
+
DebitAccount,
|
|
28
|
+
Settle,
|
|
29
|
+
Provision,
|
|
30
|
+
ProvisionFromBalance,
|
|
31
|
+
Pipe,
|
|
32
|
+
Init,
|
|
33
|
+
Destroy,
|
|
34
|
+
AllowAssets,
|
|
35
|
+
DenyAssets,
|
|
36
|
+
Allocate
|
|
37
|
+
{
|
|
38
|
+
event DepositCalled(bytes32 account, bytes32 asset, bytes32 meta, uint amount);
|
|
39
|
+
event WithdrawCalled(bytes32 account, bytes32 asset, bytes32 meta, uint amount);
|
|
40
|
+
event TransferCalled(bytes32 from_, bytes32 to_, bytes32 asset, bytes32 meta, uint amount);
|
|
41
|
+
event CreditToCalled(bytes32 account, bytes32 asset, bytes32 meta, uint amount, uint returned);
|
|
42
|
+
event DebitFromCalled(bytes32 account, bytes32 asset, bytes32 meta, uint amount, uint returned);
|
|
43
|
+
event SettleCalled(bytes32 from_, bytes32 to_, bytes32 asset, bytes32 meta, uint amount);
|
|
44
|
+
event ProvisionCalled(uint host_, bytes32 account, bytes32 asset, bytes32 meta, uint amount);
|
|
45
|
+
event InitCalled(bytes routeData);
|
|
46
|
+
event DestroyCalled(bytes routeData);
|
|
47
|
+
event AllowAssetCalled(bytes32 asset, bytes32 meta);
|
|
48
|
+
event DenyAssetCalled(bytes32 asset, bytes32 meta);
|
|
49
|
+
event AllocateCalled(uint host_, bytes32 asset, bytes32 meta, uint amount);
|
|
50
|
+
event StepDispatched(uint target, uint stepIndex, uint value);
|
|
51
|
+
|
|
52
|
+
uint public stepCount;
|
|
53
|
+
|
|
54
|
+
constructor(address rootzero) Host(rootzero, 1, "test") Deposit() Provision() Init("") Destroy("") {}
|
|
55
|
+
|
|
56
|
+
function deposit(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal override {
|
|
57
|
+
emit DepositCalled(account, asset, meta, amount);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function withdraw(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal override {
|
|
61
|
+
emit WithdrawCalled(account, asset, meta, amount);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function transfer(bytes32 from_, bytes32 to_, bytes32 asset, bytes32 meta, uint amount) internal override {
|
|
65
|
+
emit TransferCalled(from_, to_, asset, meta, amount);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function creditAccount(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal override {
|
|
69
|
+
emit CreditToCalled(account, asset, meta, amount, amount);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function debitAccount(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal override {
|
|
73
|
+
emit DebitFromCalled(account, asset, meta, amount, amount);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function settle(Tx memory value) internal override {
|
|
77
|
+
emit SettleCalled(value.from, value.to, value.asset, value.meta, value.amount);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function provision(bytes32 account, uint host_, bytes32 asset, bytes32 meta, uint amount) internal override {
|
|
81
|
+
emit ProvisionCalled(host_, account, asset, meta, amount);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function init(Block memory rawRoute) internal override {
|
|
85
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
86
|
+
emit InitCalled(routeData);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function destroy(Block memory rawRoute) internal override {
|
|
90
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
91
|
+
emit DestroyCalled(routeData);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function allowAsset(bytes32 asset, bytes32 meta) internal override returns (bool) {
|
|
95
|
+
emit AllowAssetCalled(asset, meta);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function denyAsset(bytes32 asset, bytes32 meta) internal override returns (bool) {
|
|
100
|
+
emit DenyAssetCalled(asset, meta);
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function allocate(uint host_, bytes32 asset, bytes32 meta, uint amount) internal override {
|
|
105
|
+
emit AllocateCalled(host_, asset, meta, amount);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function dispatchStep(
|
|
109
|
+
uint target,
|
|
110
|
+
bytes32,
|
|
111
|
+
bytes memory state,
|
|
112
|
+
bytes calldata,
|
|
113
|
+
uint value
|
|
114
|
+
) internal override returns (bytes memory) {
|
|
115
|
+
emit StepDispatched(target, stepCount++, value);
|
|
116
|
+
return state;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Expose internal host/admin IDs for tests
|
|
120
|
+
function getDepositId() external view returns (uint) {
|
|
121
|
+
return depositId;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function getWithdrawId() external view returns (uint) {
|
|
125
|
+
return withdrawId;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function getTransferId() external view returns (uint) {
|
|
129
|
+
return transferId;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function getCreditAccountId() external view returns (uint) {
|
|
133
|
+
return creditAccountId;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function getDebitAccountId() external view returns (uint) {
|
|
137
|
+
return debitAccountId;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function getSettleId() external view returns (uint) {
|
|
141
|
+
return settleId;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function getProvisionFromBalanceId() external view returns (uint) {
|
|
145
|
+
return provisionFromBalanceId;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function getProvisionId() external view returns (uint) {
|
|
149
|
+
return provisionId;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function getPipeId() external view returns (uint) {
|
|
153
|
+
return pipeId;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function getInitId() external view returns (uint) {
|
|
157
|
+
return initId;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function getDestroyId() external view returns (uint) {
|
|
161
|
+
return destroyId;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function getAuthorizeId() external view returns (uint) {
|
|
165
|
+
return authorizeId;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function getUnauthorizeId() external view returns (uint) {
|
|
169
|
+
return unauthorizeId;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function getRelocateId() external view returns (uint) {
|
|
173
|
+
return relocateId;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function getAllowAssetsId() external view returns (uint) {
|
|
177
|
+
return allowAssetsId;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function getDenyAssetsId() external view returns (uint) {
|
|
181
|
+
return denyAssetsId;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function getAllocateId() external view returns (uint) {
|
|
185
|
+
return allocateId;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function getAdminAccount() external view returns (bytes32) {
|
|
189
|
+
return adminAccount;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function getCommander() external view returns (address) {
|
|
193
|
+
return commander;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function isAuthorized(uint node) external view returns (bool) {
|
|
197
|
+
return authorized[node];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import { Host } from "../core/Host.sol";
|
|
5
|
+
import { AddLiquidityFromCustodiesToBalances, RemoveLiquidityFromCustodyToBalances, AddLiquidityFromBalancesToBalances, RemoveLiquidityFromBalanceToBalances } from "../commands/Liquidity.sol";
|
|
6
|
+
import { Blocks } from "../blocks/Blocks.sol";
|
|
7
|
+
import { AssetAmount, HostAmount } from "../blocks/Schema.sol";
|
|
8
|
+
import { Block, BlockPair, Writer } from "../Blocks.sol";
|
|
9
|
+
import { Writers } from "../blocks/Writers.sol";
|
|
10
|
+
import { Ids } from "../utils/Ids.sol";
|
|
11
|
+
|
|
12
|
+
using Blocks for Block;
|
|
13
|
+
using Writers for Writer;
|
|
14
|
+
|
|
15
|
+
contract TestLiquidityHost is
|
|
16
|
+
Host,
|
|
17
|
+
AddLiquidityFromCustodiesToBalances,
|
|
18
|
+
RemoveLiquidityFromCustodyToBalances,
|
|
19
|
+
AddLiquidityFromBalancesToBalances,
|
|
20
|
+
RemoveLiquidityFromBalanceToBalances
|
|
21
|
+
{
|
|
22
|
+
bytes32 internal constant LP_FROM_CUSTODIES_ASSET = bytes32(uint(0xaaa1));
|
|
23
|
+
bytes32 internal constant LP_FROM_BALANCES_ASSET = bytes32(uint(0xaaa2));
|
|
24
|
+
bytes32 internal constant REDEEM_FROM_CUSTODY_ASSET = bytes32(uint(0xbbb1));
|
|
25
|
+
bytes32 internal constant REDEEM_FROM_BALANCE_ASSET = bytes32(uint(0xbbb2));
|
|
26
|
+
|
|
27
|
+
event AddCustodiesMapped(
|
|
28
|
+
bytes32 account,
|
|
29
|
+
bytes32 assetA,
|
|
30
|
+
uint amountA,
|
|
31
|
+
bytes32 assetB,
|
|
32
|
+
uint amountB,
|
|
33
|
+
bytes routeData
|
|
34
|
+
);
|
|
35
|
+
event RemoveCustodyMapped(bytes32 account, bytes32 asset, uint amount, bytes routeData);
|
|
36
|
+
event AddBalancesMapped(
|
|
37
|
+
bytes32 account,
|
|
38
|
+
bytes32 assetA,
|
|
39
|
+
uint amountA,
|
|
40
|
+
bytes32 assetB,
|
|
41
|
+
uint amountB,
|
|
42
|
+
bytes routeData
|
|
43
|
+
);
|
|
44
|
+
event RemoveBalanceMapped(bytes32 account, bytes32 asset, uint amount, bytes routeData);
|
|
45
|
+
event MinimumObserved(bytes32 asset, bytes32 meta, uint amount);
|
|
46
|
+
|
|
47
|
+
constructor(address cmdr)
|
|
48
|
+
Host(address(0), 1, "test")
|
|
49
|
+
AddLiquidityFromCustodiesToBalances("route(bytes data)", 15_000)
|
|
50
|
+
RemoveLiquidityFromCustodyToBalances("route(bytes data)", 20_000)
|
|
51
|
+
AddLiquidityFromBalancesToBalances("route(bytes data)", 15_000)
|
|
52
|
+
RemoveLiquidityFromBalanceToBalances("route(bytes data)", 20_000)
|
|
53
|
+
{
|
|
54
|
+
if (cmdr != address(0)) access(Ids.toHost(cmdr), true);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function addLiquidityFromCustodiesToBalances(
|
|
58
|
+
bytes32 account,
|
|
59
|
+
BlockPair memory rawCustodies,
|
|
60
|
+
Block memory rawRoute,
|
|
61
|
+
Writer memory out
|
|
62
|
+
) internal override {
|
|
63
|
+
HostAmount memory a = rawCustodies.a.toCustodyValue();
|
|
64
|
+
HostAmount memory b = rawCustodies.b.toCustodyValue();
|
|
65
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
66
|
+
uint routeLen = rawRoute.bound - rawRoute.i;
|
|
67
|
+
emit AddCustodiesMapped(account, a.asset, a.amount, b.asset, b.amount, routeData);
|
|
68
|
+
emitMinimum(rawRoute);
|
|
69
|
+
|
|
70
|
+
out.appendBalance(a.asset, a.meta, a.amount + routeLen);
|
|
71
|
+
out.appendBalance(b.asset, b.meta, b.amount + routeLen + 1);
|
|
72
|
+
out.appendBalance(LP_FROM_CUSTODIES_ASSET, bytes32(routeLen), a.amount + b.amount);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function removeLiquidityFromCustodyToBalances(
|
|
76
|
+
bytes32 account,
|
|
77
|
+
HostAmount memory custody,
|
|
78
|
+
Block memory rawRoute,
|
|
79
|
+
Writer memory out
|
|
80
|
+
) internal override {
|
|
81
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
82
|
+
uint routeLen = rawRoute.bound - rawRoute.i;
|
|
83
|
+
emit RemoveCustodyMapped(account, custody.asset, custody.amount, routeData);
|
|
84
|
+
emitMinimum(rawRoute);
|
|
85
|
+
|
|
86
|
+
out.appendBalance(custody.asset, custody.meta, custody.amount + routeLen);
|
|
87
|
+
out.appendBalance(REDEEM_FROM_CUSTODY_ASSET, bytes32(routeLen), custody.amount + 10);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function addLiquidityFromBalancesToBalances(
|
|
91
|
+
bytes32 account,
|
|
92
|
+
BlockPair memory rawBalances,
|
|
93
|
+
Block memory rawRoute,
|
|
94
|
+
Writer memory out
|
|
95
|
+
) internal override {
|
|
96
|
+
AssetAmount memory a = rawBalances.a.toBalanceValue();
|
|
97
|
+
AssetAmount memory b = rawBalances.b.toBalanceValue();
|
|
98
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
99
|
+
uint routeLen = rawRoute.bound - rawRoute.i;
|
|
100
|
+
emit AddBalancesMapped(account, a.asset, a.amount, b.asset, b.amount, routeData);
|
|
101
|
+
emitMinimum(rawRoute);
|
|
102
|
+
|
|
103
|
+
out.appendBalance(a.asset, a.meta, a.amount + routeLen);
|
|
104
|
+
out.appendBalance(b.asset, b.meta, b.amount + routeLen + 2);
|
|
105
|
+
out.appendBalance(LP_FROM_BALANCES_ASSET, bytes32(routeLen), a.amount + b.amount);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function removeLiquidityFromBalanceToBalances(
|
|
109
|
+
bytes32 account,
|
|
110
|
+
AssetAmount memory balance,
|
|
111
|
+
Block memory rawRoute,
|
|
112
|
+
Writer memory out
|
|
113
|
+
) internal override {
|
|
114
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
115
|
+
uint routeLen = rawRoute.bound - rawRoute.i;
|
|
116
|
+
emit RemoveBalanceMapped(account, balance.asset, balance.amount, routeData);
|
|
117
|
+
emitMinimum(rawRoute);
|
|
118
|
+
|
|
119
|
+
out.appendBalance(balance.asset, balance.meta, balance.amount + routeLen);
|
|
120
|
+
out.appendBalance(REDEEM_FROM_BALANCE_ASSET, bytes32(routeLen), balance.amount + 20);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function emitMinimum(Block memory rawRoute) internal {
|
|
124
|
+
if (rawRoute.bound < rawRoute.end) {
|
|
125
|
+
(bytes32 asset, bytes32 meta, uint amount) = rawRoute.innerMinimum();
|
|
126
|
+
emit MinimumObserved(asset, meta, amount);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function getAddLiquidityFromCustodiesToBalancesId() external view returns (uint) {
|
|
131
|
+
return addLiquidityFromCustodiesToBalancesId;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function getRemoveLiquidityFromCustodyToBalancesId() external view returns (uint) {
|
|
135
|
+
return removeLiquidityFromCustodyToBalancesId;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function getAddLiquidityFromBalancesToBalancesId() external view returns (uint) {
|
|
139
|
+
return addLiquidityFromBalancesToBalancesId;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function getRemoveLiquidityFromBalanceToBalancesId() external view returns (uint) {
|
|
143
|
+
return removeLiquidityFromBalanceToBalancesId;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import { Host } from "../core/Host.sol";
|
|
5
|
+
import { MintToBalances } from "../commands/Mint.sol";
|
|
6
|
+
import { Block, Writer } from "../Blocks.sol";
|
|
7
|
+
import { Writers } from "../blocks/Writers.sol";
|
|
8
|
+
import { Ids } from "../utils/Ids.sol";
|
|
9
|
+
|
|
10
|
+
using Writers for Writer;
|
|
11
|
+
|
|
12
|
+
contract TestMintHost is Host, MintToBalances {
|
|
13
|
+
event MintCalled(bytes32 account, bytes routeData);
|
|
14
|
+
|
|
15
|
+
bytes32 public returnAsset;
|
|
16
|
+
bytes32 public returnMeta;
|
|
17
|
+
uint public returnAmount;
|
|
18
|
+
|
|
19
|
+
constructor(address cmdr)
|
|
20
|
+
Host(address(0), 1, "test")
|
|
21
|
+
MintToBalances("", 10_000)
|
|
22
|
+
{
|
|
23
|
+
if (cmdr != address(0)) access(Ids.toHost(cmdr), true);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function setReturn(bytes32 asset, bytes32 meta, uint amount) external {
|
|
27
|
+
returnAsset = asset;
|
|
28
|
+
returnMeta = meta;
|
|
29
|
+
returnAmount = amount;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function mintToBalances(bytes32 account, Block memory rawRoute, Writer memory out) internal override {
|
|
33
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
34
|
+
emit MintCalled(account, routeData);
|
|
35
|
+
if (returnAmount > 0) out.appendBalance(returnAsset, returnMeta, returnAmount);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getMintId() external view returns (uint) { return mintToBalancesId; }
|
|
39
|
+
function getAdminAccount() external view returns (bytes32) { return adminAccount; }
|
|
40
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import { Host } from "../core/Host.sol";
|
|
5
|
+
import { PeerPull } from "../peer/Pull.sol";
|
|
6
|
+
import { PeerPush } from "../peer/Push.sol";
|
|
7
|
+
import { Block } from "../Blocks.sol";
|
|
8
|
+
import { Ids } from "../utils/Ids.sol";
|
|
9
|
+
|
|
10
|
+
contract TestPeerHost is Host, PeerPull, PeerPush {
|
|
11
|
+
event PeerPullCalled(bytes routeData);
|
|
12
|
+
event PeerPushCalled(bytes routeData);
|
|
13
|
+
|
|
14
|
+
constructor(address cmdr)
|
|
15
|
+
Host(address(0), 1, "test")
|
|
16
|
+
PeerPull("")
|
|
17
|
+
PeerPush("")
|
|
18
|
+
{
|
|
19
|
+
if (cmdr != address(0)) access(Ids.toHost(cmdr), true);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function peerPull(Block memory rawRoute) internal override {
|
|
23
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
24
|
+
emit PeerPullCalled(routeData);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function peerPush(Block memory rawRoute) internal override {
|
|
28
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
29
|
+
emit PeerPushCalled(routeData);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getPeerPullId() external view returns (uint) { return peerPullId; }
|
|
33
|
+
function getPeerPushId() external view returns (uint) { return peerPushId; }
|
|
34
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import { Host } from "../core/Host.sol";
|
|
5
|
+
import { ReclaimToBalances } from "../commands/Reclaim.sol";
|
|
6
|
+
import { AssetAmount } from "../blocks/Schema.sol";
|
|
7
|
+
import { Block, Writer } from "../Blocks.sol";
|
|
8
|
+
import { Blocks } from "../blocks/Blocks.sol";
|
|
9
|
+
import { Writers } from "../blocks/Writers.sol";
|
|
10
|
+
import { Ids } from "../utils/Ids.sol";
|
|
11
|
+
|
|
12
|
+
using Blocks for Block;
|
|
13
|
+
using Writers for Writer;
|
|
14
|
+
|
|
15
|
+
contract TestReclaimHost is Host, ReclaimToBalances {
|
|
16
|
+
event ReclaimCalled(bytes32 account, bytes32 asset, bytes32 meta, uint amount, bytes routeData);
|
|
17
|
+
|
|
18
|
+
bytes32 public returnAsset;
|
|
19
|
+
bytes32 public returnMeta;
|
|
20
|
+
uint public returnAmount;
|
|
21
|
+
|
|
22
|
+
constructor(address cmdr)
|
|
23
|
+
Host(address(0), 1, "test")
|
|
24
|
+
ReclaimToBalances("", 10_000)
|
|
25
|
+
{
|
|
26
|
+
if (cmdr != address(0)) access(Ids.toHost(cmdr), true);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function setReturn(bytes32 asset, bytes32 meta, uint amount) external {
|
|
30
|
+
returnAsset = asset;
|
|
31
|
+
returnMeta = meta;
|
|
32
|
+
returnAmount = amount;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function reclaimToBalances(
|
|
36
|
+
bytes32 account,
|
|
37
|
+
AssetAmount memory amount,
|
|
38
|
+
Block memory rawRoute,
|
|
39
|
+
Writer memory out
|
|
40
|
+
) internal override {
|
|
41
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
42
|
+
emit ReclaimCalled(account, amount.asset, amount.meta, amount.amount, routeData);
|
|
43
|
+
if (returnAmount > 0) out.appendBalance(returnAsset, returnMeta, returnAmount);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getReclaimBalanceId() external view returns (uint) { return reclaimToBalancesId; }
|
|
47
|
+
function getAdminAccount() external view returns (bytes32) { return adminAccount; }
|
|
48
|
+
}
|
|
@@ -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 { Remove } from "../commands/Remove.sol";
|
|
6
|
+
import { Block } from "../Blocks.sol";
|
|
7
|
+
import { Ids } from "../utils/Ids.sol";
|
|
8
|
+
|
|
9
|
+
contract TestRemoveHost is Host, Remove {
|
|
10
|
+
event RemoveCalled(bytes32 account, bytes routeData);
|
|
11
|
+
|
|
12
|
+
constructor(address cmdr)
|
|
13
|
+
Host(address(0), 1, "test")
|
|
14
|
+
Remove("")
|
|
15
|
+
{
|
|
16
|
+
if (cmdr != address(0)) access(Ids.toHost(cmdr), true);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function remove(bytes32 account, Block memory rawRoute) internal override {
|
|
20
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
21
|
+
emit RemoveCalled(account, routeData);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getRemoveId() external view returns (uint) { return removeId; }
|
|
25
|
+
function getAdminAccount() external view returns (bytes32) { return adminAccount; }
|
|
26
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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, Block, Blocks } from "../Blocks.sol";
|
|
7
|
+
|
|
8
|
+
using Blocks for Block;
|
|
9
|
+
|
|
10
|
+
contract TestSwapHost is Host, SwapExactBalanceToBalance {
|
|
11
|
+
event SwapMapped(bytes32 account, bytes32 asset, bytes32 meta, uint amount, bytes routeData);
|
|
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
|
+
Block memory rawRoute
|
|
23
|
+
) internal override returns (AssetAmount memory out) {
|
|
24
|
+
bytes calldata routeData = msg.data[rawRoute.i:rawRoute.bound];
|
|
25
|
+
emit SwapMapped(account, balance.asset, balance.meta, balance.amount, routeData);
|
|
26
|
+
if (rawRoute.bound < rawRoute.end) {
|
|
27
|
+
(bytes32 minAsset, bytes32 minMeta, uint minAmount) = rawRoute.innerMinimum();
|
|
28
|
+
emit SwapMinimum(minAsset, minMeta, minAmount);
|
|
29
|
+
}
|
|
30
|
+
return AssetAmount({
|
|
31
|
+
asset: balance.asset,
|
|
32
|
+
meta: bytes32(rawRoute.bound - rawRoute.i),
|
|
33
|
+
amount: balance.amount + (rawRoute.bound - rawRoute.i)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getSwapExactInAsset32Id() external view returns (uint) {
|
|
38
|
+
return swapExactBalanceToBalanceId;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getAdminAccount() external view returns (bytes32) {
|
|
42
|
+
return adminAccount;
|
|
43
|
+
}
|
|
44
|
+
}
|