Porównaj commity

...

6 Commity

Autor SHA1 Wiadomość Data
Neeraj Kashyap 0a58731479
Merge pull request #72 from bugout-dev/vouchers
Added Voucher contract for customer f3bc...
2023-02-23 22:19:55 -08:00
Neeraj Kashyap 8a4bd49ce1 Added Voucher contract for customer f3bc... 2023-02-23 22:18:14 -08:00
Neeraj Kashyap 8911614927
Merge pull request #71 from bugout-dev/terminus-create-pool-v2
Added "createSimplePoolV2" on TerminusFacet
2023-02-23 22:01:00 -08:00
Neeraj Kashyap 086dab0181 Deployed Great Wyrm Terminus contract to wyrm chain 2023-02-17 11:18:30 -08:00
Neeraj Kashyap e836884d7b TerminusInitializer "init" method must be called by Diamond owner 2023-02-17 11:03:45 -08:00
Neeraj Kashyap 4b198dd3b4 Added "createSimplePoolV2" on TerminusFacet
Also made it so that if `requiredPayment` is set to 0 on a Terminus
contract, we will not even initiate the ERC20 `transferFrom`. This makes
it so that a Terminus contract in which the controller does not have to
pay to create a pool does not require setting a payment token.

Bumped dao version to `0.0.8`.

Added tests for `createSimplePoolV2` functionality.
2023-02-17 10:58:31 -08:00
8 zmienionych plików z 388 dodań i 31 usunięć

Wyświetl plik

@ -203,17 +203,23 @@ contract TerminusFacet is ERC1155WithTerminusStorage {
LibTerminus.enforceIsController();
LibTerminus.TerminusStorage storage ts = LibTerminus.terminusStorage();
uint256 requiredPayment = ts.poolBasePrice;
IERC20 paymentTokenContract = _paymentTokenContract();
require(
paymentTokenContract.allowance(_msgSender(), address(this)) >=
requiredPayment,
"TerminusFacet: createSimplePool -- Insufficient allowance on payment token"
);
paymentTokenContract.transferFrom(
msg.sender,
address(this),
requiredPayment
);
if (requiredPayment > 0) {
IERC20 paymentTokenContract = _paymentTokenContract();
require(
paymentTokenContract.allowance(_msgSender(), address(this)) >=
requiredPayment,
"TerminusFacet: createSimplePool -- Insufficient allowance on payment token"
);
require(
paymentTokenContract.transferFrom(
msg.sender,
address(this),
requiredPayment
),
"TerminusFacet: createSimplePool -- Transfer of payment token was unsuccessful"
);
}
return LibTerminus.createSimplePool(_capacity);
}
@ -224,19 +230,23 @@ contract TerminusFacet is ERC1155WithTerminusStorage {
) external returns (uint256) {
LibTerminus.enforceIsController();
LibTerminus.TerminusStorage storage ts = LibTerminus.terminusStorage();
// TODO(zomglings): Implement requiredPayment update based on pool features.
uint256 requiredPayment = ts.poolBasePrice;
IERC20 paymentTokenContract = _paymentTokenContract();
require(
paymentTokenContract.allowance(_msgSender(), address(this)) >=
requiredPayment,
"TerminusFacet: createPoolV1 -- Insufficient allowance on payment token"
);
paymentTokenContract.transferFrom(
msg.sender,
address(this),
requiredPayment
);
if (requiredPayment > 0) {
IERC20 paymentTokenContract = _paymentTokenContract();
require(
paymentTokenContract.allowance(_msgSender(), address(this)) >=
requiredPayment,
"TerminusFacet: createPoolV1 -- Insufficient allowance on payment token"
);
require(
paymentTokenContract.transferFrom(
msg.sender,
address(this),
requiredPayment
),
"TerminusFacet: createPoolV1 -- Transfer of payment token was unsuccessful"
);
}
uint256 poolID = LibTerminus.createSimplePool(_capacity);
if (!_transferable) {
ts.poolNotTransferable[poolID] = true;
@ -247,6 +257,42 @@ contract TerminusFacet is ERC1155WithTerminusStorage {
return poolID;
}
function createPoolV2(
uint256 _capacity,
bool _transferable,
bool _burnable,
string memory poolURI
) external returns (uint256) {
LibTerminus.enforceIsController();
LibTerminus.TerminusStorage storage ts = LibTerminus.terminusStorage();
uint256 requiredPayment = ts.poolBasePrice;
if (requiredPayment > 0) {
IERC20 paymentTokenContract = _paymentTokenContract();
require(
paymentTokenContract.allowance(_msgSender(), address(this)) >=
requiredPayment,
"TerminusFacet: createPoolV2 -- Insufficient allowance on payment token"
);
require(
paymentTokenContract.transferFrom(
msg.sender,
address(this),
requiredPayment
),
"TerminusFacet: createPoolV2 -- Transfer of payment token was unsuccessful"
);
}
uint256 poolID = LibTerminus.createSimplePool(_capacity);
if (!_transferable) {
ts.poolNotTransferable[poolID] = true;
}
if (_burnable) {
ts.poolBurnable[poolID] = true;
}
ts.poolURI[poolID] = poolURI;
return poolID;
}
function mint(
address to,
uint256 poolID,

Wyświetl plik

@ -16,6 +16,7 @@ import "./LibTerminus.sol";
contract TerminusInitializer {
function init() external {
LibDiamond.enforceIsContractOwner();
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
ds.supportedInterfaces[type(IERC1155).interfaceId] = true;
ds.supportedInterfaces[type(IERC1155MetadataURI).interfaceId] = true;

Wyświetl plik

@ -1,5 +1,5 @@
# Code generated by moonworm : https://github.com/bugout-dev/moonworm
# Moonworm version : 0.2.4
# Moonworm version : 0.6.0
import argparse
import json
@ -140,6 +140,19 @@ class TerminusFacet:
_capacity, _transferable, _burnable, transaction_config
)
def create_pool_v2(
self,
_capacity: int,
_transferable: bool,
_burnable: bool,
pool_uri: str,
transaction_config,
) -> Any:
self.assert_contract_is_instantiated()
return self.contract.createPoolV2(
_capacity, _transferable, _burnable, pool_uri, transaction_config
)
def create_simple_pool(self, _capacity: int, transaction_config) -> Any:
self.assert_contract_is_instantiated()
return self.contract.createSimplePool(_capacity, transaction_config)
@ -514,6 +527,22 @@ def handle_create_pool_v1(args: argparse.Namespace) -> None:
print(result.info())
def handle_create_pool_v2(args: argparse.Namespace) -> None:
network.connect(args.network)
contract = TerminusFacet(args.address)
transaction_config = get_transaction_config(args)
result = contract.create_pool_v2(
_capacity=args.capacity_arg,
_transferable=args.transferable_arg,
_burnable=args.burnable_arg,
pool_uri=args.pool_uri,
transaction_config=transaction_config,
)
print(result)
if args.verbose:
print(result.info())
def handle_create_simple_pool(args: argparse.Namespace) -> None:
network.connect(args.network)
contract = TerminusFacet(args.address)
@ -928,6 +957,25 @@ def generate_cli() -> argparse.ArgumentParser:
)
create_pool_v1_parser.set_defaults(func=handle_create_pool_v1)
create_pool_v2_parser = subcommands.add_parser("create-pool-v2")
add_default_arguments(create_pool_v2_parser, True)
create_pool_v2_parser.add_argument(
"--capacity-arg", required=True, help="Type: uint256", type=int
)
create_pool_v2_parser.add_argument(
"--transferable-arg",
required=True,
help="Type: bool",
type=boolean_argument_type,
)
create_pool_v2_parser.add_argument(
"--burnable-arg", required=True, help="Type: bool", type=boolean_argument_type
)
create_pool_v2_parser.add_argument(
"--pool-uri", required=True, help="Type: string", type=str
)
create_pool_v2_parser.set_defaults(func=handle_create_pool_v2)
create_simple_pool_parser = subcommands.add_parser("create-simple-pool")
add_default_arguments(create_simple_pool_parser, True)
create_simple_pool_parser.add_argument(

Wyświetl plik

@ -1093,7 +1093,7 @@ class TestPoolOperations(TerminusTestCase):
self.assertEqual(user_balance_6, user_balance_5)
class TestCreatePoolV1(TestPoolOperations):
class TestPoolCreation(TestPoolOperations):
def setUp(self):
self.diamond_terminus.create_pool_v1(10, True, False, {"from": accounts[1]})
@ -1130,7 +1130,14 @@ class TestCreatePoolV1(TestPoolOperations):
self.assertEqual(final_receiver_balance, initial_receiver_balance)
def test_pool_state_view_methods(self):
self.diamond_terminus.create_pool_v1(10, False, False, {"from": accounts[1]})
nontransferable_nonburnable_pool_uri = "https://example.com/ff.json"
self.diamond_terminus.create_pool_v2(
10,
False,
False,
nontransferable_nonburnable_pool_uri,
{"from": accounts[1]},
)
nontransferable_nonburnable_pool_id = self.diamond_terminus.total_pools()
self.assertFalse(
self.diamond_terminus.pool_is_transferable(
@ -1140,8 +1147,15 @@ class TestCreatePoolV1(TestPoolOperations):
self.assertFalse(
self.diamond_terminus.pool_is_burnable(nontransferable_nonburnable_pool_id)
)
self.assertEqual(
self.diamond_terminus.uri(nontransferable_nonburnable_pool_id),
nontransferable_nonburnable_pool_uri,
)
self.diamond_terminus.create_pool_v1(10, True, False, {"from": accounts[1]})
transferable_nonburnable_pool_uri = "https://example.com/tf.json"
self.diamond_terminus.create_pool_v2(
10, True, False, transferable_nonburnable_pool_uri, {"from": accounts[1]}
)
transferable_nonburnable_pool_id = self.diamond_terminus.total_pools()
self.assertTrue(
self.diamond_terminus.pool_is_transferable(transferable_nonburnable_pool_id)
@ -1149,8 +1163,15 @@ class TestCreatePoolV1(TestPoolOperations):
self.assertFalse(
self.diamond_terminus.pool_is_burnable(transferable_nonburnable_pool_id)
)
self.assertEqual(
self.diamond_terminus.uri(transferable_nonburnable_pool_id),
transferable_nonburnable_pool_uri,
)
self.diamond_terminus.create_pool_v1(10, True, True, {"from": accounts[1]})
transferable_burnable_pool_uri = "https://example.com/tt.json"
self.diamond_terminus.create_pool_v2(
10, True, True, transferable_burnable_pool_uri, {"from": accounts[1]}
)
transferable_burnable_pool_id = self.diamond_terminus.total_pools()
self.assertTrue(
self.diamond_terminus.pool_is_transferable(transferable_burnable_pool_id)
@ -1158,8 +1179,15 @@ class TestCreatePoolV1(TestPoolOperations):
self.assertTrue(
self.diamond_terminus.pool_is_burnable(transferable_burnable_pool_id)
)
self.assertEqual(
self.diamond_terminus.uri(transferable_burnable_pool_id),
transferable_burnable_pool_uri,
)
self.diamond_terminus.create_pool_v1(10, False, True, {"from": accounts[1]})
nontransferable_burnable_pool_uri = "https://example.com/ft.json"
self.diamond_terminus.create_pool_v2(
10, False, True, nontransferable_burnable_pool_uri, {"from": accounts[1]}
)
nontransferable_burnable_pool_id = self.diamond_terminus.total_pools()
self.assertFalse(
self.diamond_terminus.pool_is_transferable(nontransferable_burnable_pool_id)
@ -1167,6 +1195,10 @@ class TestCreatePoolV1(TestPoolOperations):
self.assertTrue(
self.diamond_terminus.pool_is_burnable(nontransferable_burnable_pool_id)
)
self.assertEqual(
self.diamond_terminus.uri(nontransferable_burnable_pool_id),
nontransferable_burnable_pool_uri,
)
def test_pool_state_setters(self):
self.diamond_terminus.create_pool_v1(10, False, False, {"from": accounts[1]})

Wyświetl plik

@ -0,0 +1 @@
{"DiamondCutFacet": "0x12e5f5dCb0F6c3771aF05a1f57c6a899665efdf1", "Diamond": "0x677441c2e95c8Cf3176dF05F45a515c2570C62a4", "DiamondLoupeFacet": "0x9EbBE32339eCA1201d14cF2487F2256966372170", "OwnershipFacet": "0x852420E735Da8d87728596585E9A67e1424B1FDE", "attached": ["DiamondLoupeFacet", "OwnershipFacet"]}

Wyświetl plik

@ -0,0 +1,114 @@
# Voucher contract
## Deployed addresses
### Diamond addresses
```json
{
"DiamondCutFacet": "0x12e5f5dCb0F6c3771aF05a1f57c6a899665efdf1",
"Diamond": "0x677441c2e95c8Cf3176dF05F45a515c2570C62a4",
"DiamondLoupeFacet": "0x9EbBE32339eCA1201d14cF2487F2256966372170",
"OwnershipFacet": "0x852420E735Da8d87728596585E9A67e1424B1FDE",
"attached": ["DiamondLoupeFacet", "OwnershipFacet"]
}
```
### `TerminusInitializer` address
```
export TERMINUS_INITIALIZER_ADDRESS="0x3d5ffae90F4F5573fC6A348B12059B2dFc5D4147"
```
### `TerminusFacet` address
```
export TERMINUS_FACET_ADDRESS="0x22F4284E1E2a1de9892a5D7c1982C7C2B403DDE9"
```
## Environment variables
- [x] `export DAO_NETWORK=polygon-main`
- [x] `export DAO_OWNER=<path to keystore file for owner account>`
- [x] `export DAO_OWNER_ADDRESS=$(jq -r .address $DAO_OWNER)`
- [x] `export MAX_FEE_PER_GAS="1000 gwei"`
- [x] `export MAX_PRIORITY_FEE_PER_GAS="100 gwei"`
- [x] `export CONFIRMATIONS=4`
- [x] `export TERMINUS_ADDRESSES=operations/customer-f3bc8a15-3b10-4be5-817e-0f16b4a31b6a/voucher.json`
## Deploy diamond proxy
- [x] Deploy diamond with all core facets
```bash
dao core gogogo \
--network $DAO_NETWORK \
--sender $DAO_OWNER \
--max-fee-per-gas "$MAX_FEE_PER_GAS" \
--max-priority-fee-per-gas "$MAX_PRIORITY_FEE_PER_GAS" \
--confirmations $CONFIRMATIONS \
--owner $DAO_OWNER_ADDRESS \
--outfile $TERMINUS_ADDRESSES
```
- [x] Store JSON output under `Deployed addresses / Diamond addresses` above.
- [x] Export diamond proxy address: `export TERMINUS_DIAMOND="$(jq -r .Diamond $TERMINUS_ADDRESSES)"`
## Deploy `TerminusInitializer`
- [ ] Deploy `TerminusInitializer` contract
```bash
dao terminus-initializer deploy \
--network $DAO_NETWORK \
--sender $DAO_OWNER \
--max-fee-per-gas "$MAX_FEE_PER_GAS" \
--max-priority-fee-per-gas "$MAX_PRIORITY_FEE_PER_GAS" \
--confirmations $CONFIRMATIONS
```
- [x] Export address of deployed contract as `export TERMINUS_INITIALIZER_ADDRESS="0x3d5ffae90F4F5573fC6A348B12059B2dFc5D4147"`
- [x] Store address of deployed contract under `Deployed addresses / TerminusInitializer address` above
## Deploy `TerminusFacet`
- [x] Deploy `TerminusFacet` contract
```bash
dao terminus deploy \
--network $DAO_NETWORK \
--sender $DAO_OWNER \
--max-fee-per-gas "$MAX_FEE_PER_GAS" \
--max-priority-fee-per-gas "$MAX_PRIORITY_FEE_PER_GAS" \
--confirmations $CONFIRMATIONS
```
- [x] Export address of deployed contract as `export TERMINUS_FACET_ADDRESS="0x22F4284E1E2a1de9892a5D7c1982C7C2B403DDE9"`
- [x] Store address of deployed contract under `Deployed addresses / TerminusFacet address` above
- [x] Attach `TerminusFacet` to diamond:
```bash
dao core facet-cut \
--address $TERMINUS_DIAMOND \
--network $DAO_NETWORK \
--sender $DAO_OWNER \
--max-fee-per-gas "$MAX_FEE_PER_GAS" \
--max-priority-fee-per-gas "$MAX_PRIORITY_FEE_PER_GAS" \
--confirmations $CONFIRMATIONS \
--facet-name TerminusFacet \
--facet-address $TERMINUS_FACET_ADDRESS \
--action add \
--initializer-address $TERMINUS_INITIALIZER_ADDRESS
```
- [x] Check the number of pools on the Terminus contract: `dao terminus total-pools --network $DAO_NETWORK --address $TERMINUS_DIAMOND`
- [x] Number of pools is `0`
- [x] Check the Terminus controller: `dao terminus terminus-controller --network $DAO_NETWORK --address $TERMINUS_DIAMOND`
- [x] Controller should be the same as `$DAO_OWNER_ADDRESS`

Wyświetl plik

@ -0,0 +1,115 @@
# The Great Wyrm Terminus contract
## Deployed addresses
### Diamond addresses
```json
{
"DiamondCutFacet": "0x59F85f5EF3ab84d0Acbebc7B7c24ea8dD13A51F6",
"Diamond": "0x49ca1F6801c085ABB165a827baDFD6742a3f8DBc",
"DiamondLoupeFacet": "0xe65507aF6BaC7d76e6Ee8944967e301e3D6aB632",
"OwnershipFacet": "0x730B911a9bE224514FC80E3df0E9D0Ad96130c2C",
"attached": [
"DiamondLoupeFacet",
"OwnershipFacet"
]
}
```
### `TerminusInitializer` address
```
export TERMINUS_INITIALIZER_ADDRESS="0xaFa971f89874D1CA2825d7fC318291984Cb82863"
```
### `TerminusFacet` address
```
export TERMINUS_FACET_ADDRESS="0x9c10710CA5797DA2878B6FA6E62eC6C1A196416C"
```
## Environment variables
- [x] `export DAO_NETWORK=wyrm`
- [x] `export DAO_OWNER=<path to keystore file for owner account>`
- [x] `export DAO_OWNER_ADDRESS=$(jq -r .address $DAO_OWNER)`
- [x] `export GAS_PRICE=0`
- [x] `export CONFIRMATIONS=1`
- [x] `export TERMINUS_ADDRESSES=<path to JSON file in which to store diamond addresses>`
## Deploy diamond proxy
- [x] Deploy diamond with all core facets
```bash
dao core gogogo \
--network $DAO_NETWORK \
--sender $DAO_OWNER \
--gas-price "$GAS_PRICE" \
--confirmations $CONFIRMATIONS \
--owner $DAO_OWNER_ADDRESS \
--outfile $TERMINUS_ADDRESSES
```
- [x] Store JSON output under `Deployed addresses / Diamond addresses` above.
- [x] Export diamond proxy address: `export TERMINUS_DIAMOND="$(jq -r .Diamond $TERMINUS_ADDRESSES)"`
## Deploy `TerminusInitializer`
- [x] Deploy `TerminusInitializer` contract
```bash
dao terminus-initializer deploy \
--network $DAO_NETWORK \
--sender $DAO_OWNER \
--gas-price "$GAS_PRICE" \
--confirmations $CONFIRMATIONS
```
- [x] Export address of deployed contract as `export TERMINUS_INITIALIZER_ADDRESS="0xaFa971f89874D1CA2825d7fC318291984Cb82863"`
- [x] Store address of deployed contract under `Deployed addresses / TerminusInitializer address` above
## Deploy `TerminusFacet`
- [x] Deploy `TerminusFacet` contract
```bash
dao terminus deploy \
--network $DAO_NETWORK \
--sender $DAO_OWNER \
--gas-price "$GAS_PRICE" \
--confirmations $CONFIRMATIONS
```
- [x] Export address of deployed contract as `export TERMINUS_FACET_ADDRESS="0x9c10710CA5797DA2878B6FA6E62eC6C1A196416C"`
- [x] Store address of deployed contract under `Deployed addresses / TerminusFacet address` above
- [x] Attach `TerminusFacet` to diamond:
```bash
dao core facet-cut \
--address $TERMINUS_DIAMOND \
--network $DAO_NETWORK \
--sender $DAO_OWNER \
--gas-price "$GAS_PRICE" \
--confirmations $CONFIRMATIONS \
--facet-name TerminusFacet \
--facet-address $TERMINUS_FACET_ADDRESS \
--action add \
--initializer-address $TERMINUS_INITIALIZER_ADDRESS
```
- [x] Check the number of pools on the Terminus contract: `dao terminus total-pools --network $DAO_NETWORK --address $TERMINUS_DIAMOND`
- [x] Number of pools is `0`
- [x] Check the Terminus controller: `dao terminus terminus-controller --network $DAO_NETWORK --address $TERMINUS_DIAMOND`
- [x] Controller should be the same as `$DAO_OWNER_ADDRESS`

Wyświetl plik

@ -6,13 +6,13 @@ with open("README.md") as ifp:
setup(
name="moonstream-dao",
version="0.0.7",
version="0.0.8",
packages=find_packages(),
install_requires=["eth-brownie", "tqdm"],
extras_require={
"dev": [
"black",
"moonworm >= 0.1.9",
"moonworm >= 0.6.0",
],
"distribute": ["setuptools", "twine", "wheel"],
},