|
| 1 | +## Yield Dex |
| 2 | + |
| 3 | +L2 contracts for Yield Dex project. |
| 4 | + |
| 5 | +### Compilation |
| 6 | + |
| 7 | +We are using Scarb to compile our contracts, you need to install it to be able to use it. |
| 8 | +For that, you can follow the steps [here](https://book.cairo-lang.org/ch01-01-installation.html). |
| 9 | +Once Scarb is installed, you are able to compile the contracts. |
| 10 | +Run `scarb build`, it will build Sierra code of this package which will be written to the `target/dev` directory. |
| 11 | + |
| 12 | +### Test |
| 13 | + |
| 14 | +You can find our tests under `src/tests`, these tests are written using snfoundry you can find more information [here](https://foundry-rs.github.io/starknet-foundry/getting-started/installation.html). |
| 15 | +Follow the installation documentation to be able to run our tests. |
| 16 | +To run the tests, just do `snforge test`. |
| 17 | + |
| 18 | +### Declare With Starkli |
| 19 | + |
| 20 | +For this, we used starkli, you need to install it to be able to declare and deploy the contracts. |
| 21 | +Once starkli is installed, you will need to set some environment variables. |
| 22 | +If you want to declare on goerli then do `export STARKNET_NETWORK="goerli"` (you replace it be mainnet or sepolia depending on the network you want to deploy to). |
| 23 | +You will have to create a signers and account, just follow those [documentation](https://book.starkli.rs/signers). |
| 24 | +Now that everything is set up, you are able to declare the contracts. |
| 25 | +For that, we will use starkli declare command, for more info check the documentation [here](https://book.starkli.rs/declaring-classes). |
| 26 | +Run `starkli declare ./target/dev/CONTRACT_NAME.contract_class.json --account PATH/account-store --network NETWORK`. |
| 27 | +`CONTRACT_NAME `the name of the json file that can be found inside `./target/dev/ `folder. |
| 28 | +`PATH/account-store` is the path to your account-store that has been previously created. |
| 29 | +`NETWORK `the name of the network you want to declare to (goerli, sepolia or mainnet). |
| 30 | +After running that, it will return to you the declared contract class hash. |
| 31 | + |
| 32 | +### Declare With Script |
| 33 | + |
| 34 | +Create a `.env` and add `ACCOUNT_ADDRESS` and `ACCOUNT_PK`. |
| 35 | +Run `npm i` to install the package. |
| 36 | +The script is deploying the contract on goerli if you want to deploy on another network then go inside `scripts/declareContracts` and change `const provider = new RpcProvider({ nodeUrl: constants.NetworkName.SN_MAIN });` with the correct network (ex: SN_GOERLI). |
| 37 | +To run the script just do `npx ts-node scripts/declareContracts.ts --contract CONTRACT_NAME.` |
| 38 | +`CONTRACT_NAME` must be replaced by : |
| 39 | +- PoolingManager |
| 40 | +- Factory |
| 41 | +- Token |
| 42 | +- TokenManager |
| 43 | + |
| 44 | +### Deploy With Starkli |
| 45 | + |
| 46 | +Now that our contracts are declared, the next step is to deploy them. For that, you can follow the documentation [here](https://book.starkli.rs/deploying-contracts). |
| 47 | +Some of the contracts take parameters in their constructor, you will need to add them in your command. |
| 48 | + |
| 49 | +PoolingManager: `starkli deploy POOLING_MANAGER_CLASS_HASH OWNER_ACCOUNT_ADDRESS --account PATH/account-store --network NETWORK` |
| 50 | +Factory: `starkli deploy FACTORY_CLASS_HASH POOLING_MANAGER_CONTRACT_ADDRESS TOKEN_CLASS_HASH TOKEN_MANAGER_CLASS_HASH --account PATH/account-store --network NETWORK` |
| 51 | + |
| 52 | +### Deploy With Script |
| 53 | + |
| 54 | +Create a `.env` and add `ACCOUNT_ADDRESS` and `ACCOUNT_PK`. |
| 55 | +Run `npm i` to install the package. |
| 56 | +The script is deploying the contract on goerli if you want to deploy on another network then go inside `scripts/deployContracts` and change `const provider = new RpcProvider({ nodeUrl: constants.NetworkName.SN_MAIN });` with the correct network (ex: `SN_GOERLI`). |
| 57 | +To run the script just do `npx ts-node scripts/deployContracts.ts --contract CONTRACT_NAME`. |
| 58 | +`CONTRACT_NAME` must be replaced by : |
| 59 | +- PoolingManager |
| 60 | +- Factory |
| 61 | + |
| 62 | +### Setup |
| 63 | +Only the owner of the contract will be able to set up the contract. |
| 64 | +You can do the setup through voyager or starkscan. |
| 65 | + |
| 66 | +PoolingManager: |
| 67 | +Only Owner: |
| 68 | +- set_fees_recipient: Address of the fees recipient. |
| 69 | +- set_l1_pooling_manager: Address of the pooling manager on l1. |
| 70 | +- set_factory: Address of the Factory contract previously deployed. |
| 71 | + |
| 72 | +Only Role, the owner has the correct role, but you can also give permission to other accounts: |
| 73 | +- register_underlying: Registers an underlying asset, its corresponding bridge contract and the corresponding address of the l1bridge |
| 74 | + |
| 75 | +Factory: |
| 76 | +Only Owner: |
| 77 | +- `deploy_strategy`: Deploys a new strategy with specified parameters. |
| 78 | +Parameters are: |
| 79 | + - l1_strategy: The Ethereum address of the L1 strategy |
| 80 | + - underlying: The contract address of the underlying asset |
| 81 | + - token_name: The name for the new token |
| 82 | + - token_symbol: The symbol for the new token |
| 83 | + - performance_fees: The performance fees for the strategy |
| 84 | + - min_deposit: The minimum deposit limit |
| 85 | + - max_deposit: The maximum deposit limit |
| 86 | + - min_withdrawal: The minimum withdrawal limit |
| 87 | + - max_withdrawal: The maximum withdrawal limit |
| 88 | + - withdrawal_epoch_delay: The delay in epochs for withdrawals |
| 89 | + - dust_limit: The dust limit for the strategy |
| 90 | +Deploy_strategy will deploy a new contract called token_manager and return you the address. We are going to use this contract to deposit some tokens. |
| 91 | + |
| 92 | +Go to the Token Manager contract address and call the deposit function, This function can be called by any user : |
| 93 | + |
| 94 | +TokenManager: |
| 95 | +- `deposit`: Allows a user to deposit assets into the contract. |
| 96 | +Parameters are: |
| 97 | + - assets: The amount of assets to deposit. |
| 98 | + - receiver: The address to receive the minted shares. |
| 99 | + - referral: The referral address for the deposit. |
| 100 | +Once users have deposited some assets, they can now request a withdrawal from the contract. |
| 101 | +- `request_withdrawal`: Allows a user to request a withdrawal from the contract |
| 102 | +Parameter is: |
| 103 | + - shares: The amount of shares to withdraw. |
| 104 | + |
| 105 | +### Goerli Class Hash |
| 106 | +You can declare a contract only once on each network. So if you don't do any modification into our current contract implementation you may face an error while declaring. Therefore here you can find the current class hash of each contract on Goerli. |
| 107 | + |
| 108 | +``` |
| 109 | +POOLINGMANAGER_CLASS_HASH="0x05adb7661d0dcb3cc5fbe69380846fb7662c92f1943fcf609c51b756cae7d411" |
| 110 | +
|
| 111 | +TOKENMANAGER_CLASS_HASH="0x03be98338455134abae1d830802a162cd81b24ddb38a868ec9c6a4341ecd7210" |
| 112 | +
|
| 113 | +TOKENMOCK_CLASS_HASH="0x00da57dbb24ceb46a3901f148442e0d591528baba485ee84ed6d4948dedf12e5" |
| 114 | +
|
| 115 | +TOKEN_CLASS_HASH="0x0720f601c0432ab03e12df99c2b215e7ab9a9c12e1b4d8b0473e18bbb3213bea" |
| 116 | +
|
| 117 | +TOKENBRIDGE_CLASS_HASH="0x00de6d9bd84775dd221273e833dc44946da586483cf822e0021385de95964700" |
| 118 | +
|
| 119 | +FACTORY_CLASS_HASH="0x0581277daf0e409c2537979108b7eb4a5cec3624db552c35f8f6acc9a3ac937b" |
| 120 | +``` |
| 121 | + |
| 122 | + |
| 123 | +### Mainnet Class Hash |
| 124 | +You can declare a contract only once on each network. So if you don't do any modification into our current contract implementation you may face an error while declaring. Therefore here you can find the current class hash of each contract on Mainnet. |
| 125 | + |
| 126 | +``` |
| 127 | +POOLINGMANAGER_CLASS_HASH=0x05adb7661d0dcb3cc5fbe69380846fb7662c92f1943fcf609c51b756cae7d411 |
| 128 | +
|
| 129 | +FACTORY_CLASS_HASH=0x581277daf0e409c2537979108b7eb4a5cec3624db552c35f8f6acc9a3ac937b |
| 130 | +
|
| 131 | +TOKENMANAGER_CLASS_HASH=0x3be98338455134abae1d830802a162cd81b24ddb38a868ec9c6a4341ecd7210 |
| 132 | +
|
| 133 | +TOKEN_CLASS_HASH=0x720f601c0432ab03e12df99c2b215e7ab9a9c12e1b4d8b0473e18bbb3213bea |
| 134 | +``` |
| 135 | + |
| 136 | + |
0 commit comments