-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added example application lending protocol to academy #473
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea to add some examples from the team. A good first step in something folks will need. In my opinion, the most important goal behind this would be to offer coding patterns developers can easily copy into their application code, and not necessarily templates for production applications.
That being said I think this is too complex for a quickly digestible example of which the goal should be to teach programming patterns unique to =nil;.
I say we simplify this way further. In particular LendingPool.sol
, we should keep the showcase of cross-shard calls with callbacks and isolated storage, but let's simplify the code and make it less about the lending protocol and more about the programming patterns being used, and explaining them and how to use them.
Let's also combine the Implementation Guide.md
and Understanding-Lending-Protocol.md
into a single markdown file, perhaps titled patterns.md
that focuses on explaining:
- a simple visual representation of how the contracts interact (step 1 here, step 2 there, etc.)
- the nil-specific programming patterns seen in the example
academy/README.md
Outdated
|
||
```sh | ||
git clone https://github.com/nilfoundation/nil | ||
cd nil/dapp-examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cd nil/dapp-examples | |
cd academy/lending-protocol |
academy/lending-protocol/README.md
Outdated
``` | ||
2. 📂 Navigate to the project root and install dependencies: | ||
```sh | ||
cd nil/dapp-examples/lending-protocol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cd nil/dapp-examples/lending-protocol | |
cd nil/academy/lending-protocol |
``` | ||
4. 🚀 Run the end-to-end lending workflow: | ||
```sh | ||
npx hardhat run-lending-protocol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This step gives me:
npx hardhat run-lending-protocol
(node:42149) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Faucet client created
Deploying Wallet
Deployer smart account generated at 0x0001f485a3f895138f387c1738131d0fcad30cc4
An unexpected error occurred:
JSONRPCError: Do not know how to serialize a BigInt
at new JSONRPCError (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/Error.js:24:28)
at HTTPTransport.<anonymous> (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/transports/HTTPTransport.js:122:39)
at step (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/transports/HTTPTransport.js:46:23)
at Object.next (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/transports/HTTPTransport.js:27:53)
at /Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/transports/HTTPTransport.js:21:71
at new Promise (<anonymous>)
at __awaiter (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/transports/HTTPTransport.js:17:12)
at HTTPTransport.sendData (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/transports/HTTPTransport.js:84:16)
at RequestManager.<anonymous> (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/RequestManager.js:96:66)
at step (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/RequestManager.js:33:23) {
code: 7979,
data: TypeError: Do not know how to serialize a BigInt
at JSON.stringify (<anonymous>)
at HTTPTransport.<anonymous> (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/transports/HTTPTransport.js:99:44)
at step (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/transports/HTTPTransport.js:46:23)
at Object.next (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/transports/HTTPTransport.js:27:53)
at /Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/transports/HTTPTransport.js:21:71
at new Promise (<anonymous>)
at __awaiter (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/transports/HTTPTransport.js:17:12)
at HTTPTransport.sendData (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/transports/HTTPTransport.js:84:16)
at RequestManager.<anonymous> (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/RequestManager.js:96:66)
at step (/Users/dennis/Documents/Code/nil/nil/academy/lending-protocol/node_modules/@open-rpc/client-js/build/RequestManager.js:33:23)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing usage of BigInt()
in faucet
methods fixed this in the task file
1. 📥 Clone the repository: | ||
```sh | ||
git clone https://github.com/NilFoundation/nil.git | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would help to include here to set RPC and Private Key in .env
{ | ||
smartAccountAddress: deployerWallet.address, | ||
faucetAddress: process.env.USDT as `0x${string}`, | ||
amount: BigInt(3000), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will error when deps are installed with current package.json config.
Once removed in all uses of this function the task execution runs as expected
|
||
This project illustrates the power of **sharded smart contract design** in building decentralized finance applications. By isolating different tasks into specialized contracts, we achieve: | ||
|
||
- **Better performance:** Contracts can handle specific tasks independently and concurrently, reducing delays. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, not entirely true if the trx is dependent on callbacks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concurrently, yes because, I can send 2 to 3 messages in the same function like lets say, I can use asyncCall and sendTokens and both happen on their respective shards concurrently, afaiu
|
||
- **Better performance:** Contracts can handle specific tasks independently and concurrently, reducing delays. | ||
- **Lower gas costs:** Gas fees are minimized by avoiding unnecessary state changes in contracts that don’t need to be updated. | ||
- **Easier upgrades and maintenance:** With separate contracts, you can upgrade one piece of the system without disrupting the entire protocol. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't shown in this example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file focuses too much on a theoretical dApp design and could better be left out
- **GlobalLedger** (Shard 3) | ||
- **Oracle** (Shard 4) | ||
- **LendingPool** (Shard 1) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should be clear that we deploy on different shards to illustrate the programming patterns you can implement with =nil;. App design recommendations are case-specific and out-of-scope here anyway
|
||
When a user deposits tokens into the **LendingPool**, the following steps occur: | ||
|
||
1. **Deposit Transaction**: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A step-by-step walkthrough through a call on the contract is not really necessary here, or helpful IMO.
It's more valuable to highlight in a visual how the contracts call each other and what the method names called are in this visual. In code you can show the nil-specific syntax, like sendRequest()
and explain how that works, what the params are for.
Again, the purpose of the examples is:
- To showcase nil-specific programming patterns
- Give devs easy to find and copy for use code snippets for their own purposes
47c8bc9
to
5fb065e
Compare
5fb065e
to
ed23827
Compare
ed23827
to
fbdd62d
Compare
This PR serves as an initiative to the Academy that will have all the dApp examples to help developers understand how to develop on top of =nil;. This particular PR adds an example dApp which is a lending protocol to the academy.
The lending protocol serves as a basic defi application which can be used to understand something's such as how to work with tokens, async methods and how to design smart contracts for a sharded network. It includes contracts and hardhat tasks required for working of the lending protocol. It also comes with a
implementation guide
for a deep dive into the implementation and aunderstanding lending protocol
guide which explains the thesis of this application.