@fastish/contracts 0.1.0 → 0.1.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/Blocks.sol +73 -0
- package/Commands.sol +47 -0
- package/Core.sol +10 -0
- package/Events.sol +18 -0
- package/README.md +18 -18
- package/Schema.sol +57 -0
- package/Utils.sol +105 -0
- package/package.json +2 -1
package/Blocks.sol
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ALLOCATION,
|
|
6
|
+
ALLOCATION_KEY,
|
|
7
|
+
AMOUNT,
|
|
8
|
+
AMOUNT_KEY,
|
|
9
|
+
ASSET,
|
|
10
|
+
ASSET_KEY,
|
|
11
|
+
AUTH,
|
|
12
|
+
AUTH_KEY,
|
|
13
|
+
BALANCE,
|
|
14
|
+
BALANCE_KEY,
|
|
15
|
+
BOUNTY,
|
|
16
|
+
BOUNTY_KEY,
|
|
17
|
+
BlockRef,
|
|
18
|
+
CUSTODY,
|
|
19
|
+
CUSTODY_KEY,
|
|
20
|
+
DataRef,
|
|
21
|
+
DataPairRef,
|
|
22
|
+
FUNDING,
|
|
23
|
+
FUNDING_KEY,
|
|
24
|
+
HostAmount,
|
|
25
|
+
LISTING,
|
|
26
|
+
LISTING_KEY,
|
|
27
|
+
Listing,
|
|
28
|
+
MAXIMUM,
|
|
29
|
+
MAXIMUM_KEY,
|
|
30
|
+
MINIMUM,
|
|
31
|
+
MINIMUM_KEY,
|
|
32
|
+
MemRef,
|
|
33
|
+
NODE,
|
|
34
|
+
NODE_KEY,
|
|
35
|
+
QUANTITY,
|
|
36
|
+
QUANTITY_KEY,
|
|
37
|
+
PARTY,
|
|
38
|
+
PARTY_KEY,
|
|
39
|
+
RATE,
|
|
40
|
+
RATE_KEY,
|
|
41
|
+
RECIPIENT,
|
|
42
|
+
RECIPIENT_KEY,
|
|
43
|
+
ROUTE,
|
|
44
|
+
ROUTE_EMPTY,
|
|
45
|
+
ROUTE_KEY,
|
|
46
|
+
STEP,
|
|
47
|
+
STEP_KEY,
|
|
48
|
+
TX,
|
|
49
|
+
TX_KEY,
|
|
50
|
+
Tx,
|
|
51
|
+
Writer,
|
|
52
|
+
AssetAmount
|
|
53
|
+
} from "./contracts/blocks/Schema.sol";
|
|
54
|
+
import {Blocks} from "./contracts/blocks/Readers.sol";
|
|
55
|
+
import {Data} from "./contracts/blocks/Data.sol";
|
|
56
|
+
import {Mem} from "./contracts/blocks/Mem.sol";
|
|
57
|
+
import {
|
|
58
|
+
InvalidBlock,
|
|
59
|
+
MalformedBlocks,
|
|
60
|
+
UnexpectedAsset,
|
|
61
|
+
UnexpectedHost,
|
|
62
|
+
UnexpectedMeta,
|
|
63
|
+
ZeroNode,
|
|
64
|
+
ZeroRecipient
|
|
65
|
+
} from "./contracts/blocks/Errors.sol";
|
|
66
|
+
import {
|
|
67
|
+
BALANCE_BLOCK_LEN,
|
|
68
|
+
CUSTODY_BLOCK_LEN,
|
|
69
|
+
IncompleteWriter,
|
|
70
|
+
TX_BLOCK_LEN,
|
|
71
|
+
Writers,
|
|
72
|
+
WriterOverflow
|
|
73
|
+
} from "./contracts/blocks/Writers.sol";
|
package/Commands.sol
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {CommandBase, CommandContext} from "./contracts/commands/Base.sol";
|
|
5
|
+
import {NoOperation} from "./contracts/core/Operation.sol";
|
|
6
|
+
import {BALANCES, CLAIMS, CUSTODIES, PIPE, SETUP, TRANSACTIONS} from "./contracts/utils/Channels.sol";
|
|
7
|
+
import {BorrowAgainstBalanceToBalance, BorrowAgainstCustodyToBalance} from "./contracts/commands/Borrow.sol";
|
|
8
|
+
import {Burn} from "./contracts/commands/Burn.sol";
|
|
9
|
+
import {Create} from "./contracts/commands/Create.sol";
|
|
10
|
+
import {CreditBalanceToAccount} from "./contracts/commands/CreditTo.sol";
|
|
11
|
+
import {DebitAccountToBalance} from "./contracts/commands/DebitFrom.sol";
|
|
12
|
+
import {Deposit} from "./contracts/commands/Deposit.sol";
|
|
13
|
+
import {Remove} from "./contracts/commands/Remove.sol";
|
|
14
|
+
import {Fund} from "./contracts/commands/Fund.sol";
|
|
15
|
+
import {
|
|
16
|
+
AddLiquidityFromBalancesToBalances,
|
|
17
|
+
AddLiquidityFromCustodiesToBalances,
|
|
18
|
+
RemoveLiquidityFromBalanceToBalances,
|
|
19
|
+
RemoveLiquidityFromCustodyToBalances
|
|
20
|
+
} from "./contracts/commands/Liquidity.sol";
|
|
21
|
+
import {LiquidateFromBalanceToBalances, LiquidateFromCustodyToBalances} from "./contracts/commands/Liquidate.sol";
|
|
22
|
+
import {MintToBalances} from "./contracts/commands/Mint.sol";
|
|
23
|
+
import {Pipe} from "./contracts/commands/Pipe.sol";
|
|
24
|
+
import {Provision} from "./contracts/commands/Provision.sol";
|
|
25
|
+
import {ReclaimToBalances} from "./contracts/commands/Reclaim.sol";
|
|
26
|
+
import {RedeemFromBalanceToBalances, RedeemFromCustodyToBalances} from "./contracts/commands/Redeem.sol";
|
|
27
|
+
import {RepayFromBalanceToBalances, RepayFromCustodyToBalances} from "./contracts/commands/Repay.sol";
|
|
28
|
+
import {Settle} from "./contracts/commands/Settle.sol";
|
|
29
|
+
import {StakeBalanceToBalances, StakeCustodyToBalances, StakeCustodyToPosition} from "./contracts/commands/Stake.sol";
|
|
30
|
+
import {Supply} from "./contracts/commands/Supply.sol";
|
|
31
|
+
import {SwapExactBalanceToBalance, SwapExactCustodyToBalance} from "./contracts/commands/Swap.sol";
|
|
32
|
+
import {Transfer} from "./contracts/commands/Transfer.sol";
|
|
33
|
+
import {UnstakeBalanceToBalances} from "./contracts/commands/Unstake.sol";
|
|
34
|
+
import {Withdraw} from "./contracts/commands/Withdraw.sol";
|
|
35
|
+
import {AllowAssets} from "./contracts/commands/admin/AllowAssets.sol";
|
|
36
|
+
import {Destroy} from "./contracts/commands/admin/Destroy.sol";
|
|
37
|
+
import {Authorize} from "./contracts/commands/admin/Authorize.sol";
|
|
38
|
+
import {DenyAssets} from "./contracts/commands/admin/DenyAssets.sol";
|
|
39
|
+
import {Init} from "./contracts/commands/admin/Init.sol";
|
|
40
|
+
import {Relocate} from "./contracts/commands/admin/Relocate.sol";
|
|
41
|
+
import {Allocate} from "./contracts/commands/admin/Allocate.sol";
|
|
42
|
+
import {Unauthorize} from "./contracts/commands/admin/Unauthorize.sol";
|
|
43
|
+
import {PeerBase} from "./contracts/peer/Base.sol";
|
|
44
|
+
import {PeerAllowAssets} from "./contracts/peer/AllowAssets.sol";
|
|
45
|
+
import {PeerDenyAssets} from "./contracts/peer/DenyAssets.sol";
|
|
46
|
+
import {PeerPull} from "./contracts/peer/Pull.sol";
|
|
47
|
+
import {PeerPush} from "./contracts/peer/Push.sol";
|
package/Core.sol
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {AccessControl} from "./contracts/core/Access.sol";
|
|
5
|
+
import {Balances} from "./contracts/core/Balances.sol";
|
|
6
|
+
import {Host} from "./contracts/core/Host.sol";
|
|
7
|
+
import {FailedCall, NoOperation, OperationBase} from "./contracts/core/Operation.sol";
|
|
8
|
+
import {Validator} from "./contracts/core/Validator.sol";
|
|
9
|
+
import {HostDiscovery} from "./contracts/core/Host.sol";
|
|
10
|
+
import {IHostDiscovery} from "./contracts/interfaces/IHostDiscovery.sol";
|
package/Events.sol
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {AccessEvent} from "./contracts/events/Access.sol";
|
|
5
|
+
import {AssetEvent} from "./contracts/events/Asset.sol";
|
|
6
|
+
import {BalanceEvent} from "./contracts/events/Balance.sol";
|
|
7
|
+
import {CollateralEvent} from "./contracts/events/Collateral.sol";
|
|
8
|
+
import {CommandEvent} from "./contracts/events/Command.sol";
|
|
9
|
+
import {DebtEvent} from "./contracts/events/Debt.sol";
|
|
10
|
+
import {DepositEvent} from "./contracts/events/Deposit.sol";
|
|
11
|
+
import {EventEmitter} from "./contracts/events/Emitter.sol";
|
|
12
|
+
import {GovernedEvent} from "./contracts/events/Governed.sol";
|
|
13
|
+
import {HostAnnouncedEvent} from "./contracts/events/HostAnnounced.sol";
|
|
14
|
+
import {ListingEvent} from "./contracts/events/Listing.sol";
|
|
15
|
+
import {PeerEvent} from "./contracts/events/Peer.sol";
|
|
16
|
+
import {QuoteEvent} from "./contracts/events/Quote.sol";
|
|
17
|
+
import {FastishEvent} from "./contracts/events/Fastish.sol";
|
|
18
|
+
import {WithdrawalEvent} from "./contracts/events/Withdraw.sol";
|
package/README.md
CHANGED
|
@@ -11,15 +11,15 @@ It contains the reusable contracts, utilities, and encoding helpers that Fastish
|
|
|
11
11
|
- Shared request/response block parsing and writing logic
|
|
12
12
|
- Shared id, asset, account, and event encoding used across the protocol
|
|
13
13
|
|
|
14
|
-
## Main Entry Points
|
|
15
|
-
|
|
16
|
-
Most consumers should start from the
|
|
17
|
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
14
|
+
## Main Entry Points
|
|
15
|
+
|
|
16
|
+
Most consumers should start from the package root entrypoints:
|
|
17
|
+
|
|
18
|
+
- `@fastish/contracts/Core.sol`: core host and validation building blocks
|
|
19
|
+
- `@fastish/contracts/Commands.sol`: base command contract plus standard command mixins
|
|
20
|
+
- `@fastish/contracts/Blocks.sol`: block schema, readers, and writers
|
|
21
|
+
- `@fastish/contracts/Utils.sol`: ids, assets, accounts, layout, strings, and value helpers
|
|
22
|
+
- `@fastish/contracts/Events.sol`: reusable event emitters and event contracts
|
|
23
23
|
|
|
24
24
|
## Start Here
|
|
25
25
|
|
|
@@ -44,7 +44,7 @@ Extend `Host` when you want a Fastish host contract with admin command support a
|
|
|
44
44
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
45
45
|
pragma solidity ^0.8.33;
|
|
46
46
|
|
|
47
|
-
import {Host} from "fastish/contracts/Core.sol";
|
|
47
|
+
import {Host} from "@fastish/contracts/Core.sol";
|
|
48
48
|
|
|
49
49
|
contract ExampleHost is Host {
|
|
50
50
|
constructor(address fastish)
|
|
@@ -69,7 +69,7 @@ Extend `CommandBase` when you want a Fastish command mixin that runs inside the
|
|
|
69
69
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
70
70
|
pragma solidity ^0.8.33;
|
|
71
71
|
|
|
72
|
-
import {CommandBase, CommandContext} from "fastish/contracts/Commands.sol";
|
|
72
|
+
import {CommandBase, CommandContext} from "@fastish/contracts/Commands.sol";
|
|
73
73
|
|
|
74
74
|
string constant NAME = "myCommand";
|
|
75
75
|
string constant ROUTE = "route(uint foo, uint bar)";
|
|
@@ -114,13 +114,13 @@ npm install @fastish/contracts
|
|
|
114
114
|
npm run compile
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
The stable import surface for consumers is:
|
|
118
|
-
|
|
119
|
-
-
|
|
120
|
-
-
|
|
121
|
-
-
|
|
122
|
-
-
|
|
123
|
-
-
|
|
117
|
+
The stable import surface for consumers is:
|
|
118
|
+
|
|
119
|
+
- `@fastish/contracts/Core.sol`
|
|
120
|
+
- `@fastish/contracts/Commands.sol`
|
|
121
|
+
- `@fastish/contracts/Blocks.sol`
|
|
122
|
+
- `@fastish/contracts/Utils.sol`
|
|
123
|
+
- `@fastish/contracts/Events.sol`
|
|
124
124
|
|
|
125
125
|
## When To Use This Repo
|
|
126
126
|
|
package/Schema.sol
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ALLOCATION,
|
|
6
|
+
ALLOCATION_KEY,
|
|
7
|
+
AMOUNT,
|
|
8
|
+
AMOUNT_KEY,
|
|
9
|
+
ASSET,
|
|
10
|
+
ASSET_KEY,
|
|
11
|
+
AUTH,
|
|
12
|
+
AUTH_KEY,
|
|
13
|
+
AUTH_PROOF_LEN,
|
|
14
|
+
AUTH_TOTAL_LEN,
|
|
15
|
+
BALANCE,
|
|
16
|
+
BALANCE_KEY,
|
|
17
|
+
BOUNTY,
|
|
18
|
+
BOUNTY_KEY,
|
|
19
|
+
BlockPairRef,
|
|
20
|
+
BlockRef,
|
|
21
|
+
CUSTODY,
|
|
22
|
+
CUSTODY_KEY,
|
|
23
|
+
DataPairRef,
|
|
24
|
+
DataRef,
|
|
25
|
+
FUNDING,
|
|
26
|
+
FUNDING_KEY,
|
|
27
|
+
HostAmount,
|
|
28
|
+
UserAmount,
|
|
29
|
+
LISTING,
|
|
30
|
+
LISTING_KEY,
|
|
31
|
+
Listing,
|
|
32
|
+
MAXIMUM,
|
|
33
|
+
MAXIMUM_KEY,
|
|
34
|
+
MINIMUM,
|
|
35
|
+
MINIMUM_KEY,
|
|
36
|
+
MemRef,
|
|
37
|
+
NODE,
|
|
38
|
+
NODE_KEY,
|
|
39
|
+
QUANTITY,
|
|
40
|
+
QUANTITY_KEY,
|
|
41
|
+
PARTY,
|
|
42
|
+
PARTY_KEY,
|
|
43
|
+
RATE,
|
|
44
|
+
RATE_KEY,
|
|
45
|
+
RECIPIENT,
|
|
46
|
+
RECIPIENT_KEY,
|
|
47
|
+
ROUTE,
|
|
48
|
+
ROUTE_EMPTY,
|
|
49
|
+
ROUTE_KEY,
|
|
50
|
+
STEP,
|
|
51
|
+
STEP_KEY,
|
|
52
|
+
TX,
|
|
53
|
+
TX_KEY,
|
|
54
|
+
Tx,
|
|
55
|
+
Writer,
|
|
56
|
+
AssetAmount
|
|
57
|
+
} from "./contracts/blocks/Schema.sol";
|
package/Utils.sol
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
CLAIMS,
|
|
6
|
+
BALANCES,
|
|
7
|
+
CUSTODIES,
|
|
8
|
+
PIPE,
|
|
9
|
+
SETUP,
|
|
10
|
+
TRANSACTIONS
|
|
11
|
+
} from "./contracts/utils/Channels.sol";
|
|
12
|
+
import {
|
|
13
|
+
ACCOUNT_FAMILY,
|
|
14
|
+
accountEvmAddr,
|
|
15
|
+
accountPrefix,
|
|
16
|
+
addrOr,
|
|
17
|
+
ADMIN_PREFIX,
|
|
18
|
+
ensureEvmAccount,
|
|
19
|
+
InvalidAccount,
|
|
20
|
+
isAdminAccount,
|
|
21
|
+
toAdminAccount,
|
|
22
|
+
toUserAccount,
|
|
23
|
+
USER_PREFIX
|
|
24
|
+
} from "./contracts/utils/Accounts.sol";
|
|
25
|
+
import {
|
|
26
|
+
BadAmount,
|
|
27
|
+
ensureAmount,
|
|
28
|
+
ensureAssetRef,
|
|
29
|
+
ensureBalanceRef,
|
|
30
|
+
ERC20_PREFIX,
|
|
31
|
+
ERC721_PREFIX,
|
|
32
|
+
InvalidAsset,
|
|
33
|
+
isAsset32,
|
|
34
|
+
localErc20Addr,
|
|
35
|
+
localErc721Issuer,
|
|
36
|
+
resolveAmount,
|
|
37
|
+
toErc20Asset,
|
|
38
|
+
toErc721Asset,
|
|
39
|
+
toValueAsset,
|
|
40
|
+
VALUE_PREFIX,
|
|
41
|
+
ZeroAmount
|
|
42
|
+
} from "./contracts/utils/Assets.sol";
|
|
43
|
+
import {ECDSA} from "./contracts/utils/ECDSA.sol";
|
|
44
|
+
import {
|
|
45
|
+
COMMAND_ARGS,
|
|
46
|
+
COMMAND_PREFIX,
|
|
47
|
+
ensureCommand,
|
|
48
|
+
ensureHost,
|
|
49
|
+
HOST_PREFIX,
|
|
50
|
+
InvalidId,
|
|
51
|
+
isCommand,
|
|
52
|
+
isHost,
|
|
53
|
+
isPeer,
|
|
54
|
+
localHostAddr,
|
|
55
|
+
localNodeAddr,
|
|
56
|
+
NODE_FAMILY,
|
|
57
|
+
PEER_ARGS,
|
|
58
|
+
PEER_PREFIX,
|
|
59
|
+
toCommandId,
|
|
60
|
+
toCommandSelector,
|
|
61
|
+
toHostId,
|
|
62
|
+
toPeerId,
|
|
63
|
+
toPeerSelector
|
|
64
|
+
} from "./contracts/utils/Ids.sol";
|
|
65
|
+
import {
|
|
66
|
+
ACCOUNT,
|
|
67
|
+
ADMIN,
|
|
68
|
+
ASSET,
|
|
69
|
+
COMMAND,
|
|
70
|
+
ERC20,
|
|
71
|
+
ERC721,
|
|
72
|
+
EVM32,
|
|
73
|
+
EVM64,
|
|
74
|
+
HOST,
|
|
75
|
+
NODE,
|
|
76
|
+
PEER,
|
|
77
|
+
USER,
|
|
78
|
+
VALUE
|
|
79
|
+
} from "./contracts/utils/Layout.sol";
|
|
80
|
+
import {bytes32ToString} from "./contracts/utils/Strings.sol";
|
|
81
|
+
import {
|
|
82
|
+
applyBps,
|
|
83
|
+
beforeBps,
|
|
84
|
+
isFamily,
|
|
85
|
+
isLocal,
|
|
86
|
+
isLocalFamily,
|
|
87
|
+
matchesBase,
|
|
88
|
+
MAX_BPS,
|
|
89
|
+
max8,
|
|
90
|
+
max16,
|
|
91
|
+
max24,
|
|
92
|
+
max32,
|
|
93
|
+
max40,
|
|
94
|
+
max64,
|
|
95
|
+
max96,
|
|
96
|
+
max128,
|
|
97
|
+
max160,
|
|
98
|
+
routeSchema1,
|
|
99
|
+
routeSchema2,
|
|
100
|
+
toLocalBase,
|
|
101
|
+
toLocalFamily,
|
|
102
|
+
toUnspecifiedBase,
|
|
103
|
+
ValueOverflow
|
|
104
|
+
} from "./contracts/utils/Utils.sol";
|
|
105
|
+
import {InsufficientValue, msgValue, useValue, ValueBudget} from "./contracts/utils/Value.sol";
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastish/contracts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Solidity contracts and protocol building blocks for Fastish hosts and commands.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "GPL-3.0-only",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"files": [
|
|
9
|
+
"*.sol",
|
|
9
10
|
"contracts/**/*.sol",
|
|
10
11
|
"README.md",
|
|
11
12
|
"LICENSE"
|