Skip to content

Commit 1ac4c26

Browse files
committed
Final submission
1 parent 88eff75 commit 1ac4c26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2326
-1295
lines changed

7-defi-devpost/kl_protocol/README.md

+40-1
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,43 @@ Another feature made available by the LendingPoolManager is liquidation. Liquida
8181

8282

8383

84-
There are two types of liquidation: The manual liquidation, that is available to any user and auto_liquidation that is reserved to admin batch liquidation. Both have different mechanics. Manual liquidation targets a specific collateral that the liquidator wants and provides required loan payment to get the liquidation to happen. On the other end, auto_liquidation analyzes the whole CDP and performs direct asset sales to improve the health factor.
84+
There are two types of liquidation: The manual liquidation, that is available to any user and auto_liquidation that is reserved to admin batch liquidation. Both have different mechanics. Manual liquidation targets a specific collateral that the liquidator wants and provides required loan payment to get the liquidation to happen. On the other end, auto_liquidation analyzes the whole CDP and performs direct asset sales to improve the health factor.
85+
86+
nter image description here](https://res.cloudinary.com/daisvxhyu/image/upload/v1679682535/action_flow_fxh6v4.png)
87+
88+
## Testing
89+
90+
KL Protocol is shipped with a fully function App available to try feature like lending and borrowing. Not all feature from the blueprint are implemented like multiple interns rate scheme. and flash loan to swap debit or collateral. For a compete test of all feature, we create some resim tests script written in Javascript using google ZX library. testing script are in the /simulation forder and can be run using the command:
91+
92+
cd simulation
93+
npm i
94+
npm start
95+
96+
The user interface is a Sveltkit project using the Radix Developper Toolkit to interact with the Radix Betanet.
97+
To get started, navigate to the /frontend folder and run
98+
99+
cd frontend
100+
npm i
101+
nmp run dev
102+
103+
This will spin p a dev server and you will get and home page with tree menu option. Cliec the admin menu this will give you the Dap setup page as show bellow:
104+
105+
![Admin menu for setting app KL Protocol](https://res.cloudinary.com/daisvxhyu/image/upload/v1679684371/Radix/ui_setup.png)
106+
107+
Once the setup complete the admin app will look like the picture bellow. the admin screen also make possible to change price of Faucet asset to help simulate variation on loan heal factors.
108+
109+
![Setup completed](https://res.cloudinary.com/daisvxhyu/image/upload/v1679684371/Radix/ui_setup_completed.png)
110+
111+
From there you can go to the Faucet menu to get some test resources:
112+
113+
![Faucet for test resources](https://res.cloudinary.com/daisvxhyu/image/upload/v1679684370/Radix/faucet.png)
114+
115+
Now we can go to the App menu and start playing with the protocol. For the borrowing feature, you will need to mint a CDP NFT :
116+
117+
![CDP NFT Is required for borring](https://res.cloudinary.com/daisvxhyu/image/upload/v1679684370/Radix/borrowing_first_pages.png)
118+
119+
Some screenshot of the DAPP:
120+
121+
![The BORROW page](https://res.cloudinary.com/daisvxhyu/image/upload/v1679684370/Radix/borrowing.png)
122+
123+
![The LENDING page](https://res.cloudinary.com/daisvxhyu/image/upload/v1679684372/Radix/lending.png)
Loading
Loading
Loading
Loading
Loading
Loading
Loading
+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
Tx ID
2-
829c45f749c4ca86765132e45a4bb6b3b7a2e830775336eb511db97f6e5ac4cb
2+
c18ae6fb1e217d5c17d2f7f5bf445578b64e90887fc58a55ec3f5cda83071899
33
Package address
4-
package_tdx_b_1qy8fdtykc2m0kuprfqy6cxk88r938rr4ty8zyxlcdfxq9srfny
4+
package_tdx_b_1q8c5vknglhcqw7nrg83yrwmrhy69xndpk4ndmnect29s7n56us
55

6-
7-
a58ac3bf64665067c87bcca05a5d6905257f4e70b69ec222e44041e7d603cb85
8-
component_tdx_b_1q25sgetk4q4r4znhpgzj4ypdk8uqxv74edcjh72t7xysg398qd
6+
30844b13b5856810ca7a213d7b7424d43ab22a3b5623b048d0f6a08d8fd23a99
7+
e92b9a78f25c8ae4b884fd2a172e02ae29434d4f0ba5e77dfa70b2261e0e8735

7-defi-devpost/kl_protocol/frontend/package-lock.json

+10-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

7-defi-devpost/kl_protocol/frontend/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@svelteuidev/core": "^0.10.0",
3535
"radix-icons-svelte": "^1.2.1",
3636
"svelte-forms": "^2.3.1",
37-
"svelte-local-storage-store": "^0.4.0"
37+
"svelte-local-storage-store": "^0.4.0",
38+
"svelte-modals": "^1.2.1"
3839
}
3940
}

7-defi-devpost/kl_protocol/frontend/src/lib/data.ts renamed to 7-defi-devpost/kl_protocol/frontend/src/data.ts

+19-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
import { persisted } from "svelte-local-storage-store";
2-
import { XRD } from "./transactions/admin";
1+
2+
3+
4+
// export const TIME_FACTOR = 32
5+
export const INTEREST_RATE_TYPE = 1
6+
export const XRD = 'resource_tdx_b_1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq8z96qp'
7+
export const DAPP_ID = ''
8+
export const PACKAGE_ADDRESS = ''
39

410
export type PoolInfo = {
511
//
@@ -18,36 +24,18 @@ export type PoolInfo = {
1824
liquidation_closing_factor: number;
1925
}
2026

21-
let _price_chages: Record<string, number> = {}
22-
23-
export const price_changes = persisted('price_changes', _price_chages)
24-
25-
export const dapp_data = persisted('persited_data', {
26-
accountAddress: '',
27-
dAppId: 'account_tdx_b_1pqwzpeqv8mph3u80g5zch24gtpky3wy3demlg6ta6q4qhkdpd8',
28-
packageAddress: 'package_tdx_b_1qy8fdtykc2m0kuprfqy6cxk88r938rr4ty8zyxlcdfxq9srfny',
29-
30-
faucetComponentAddress: '',
31-
faucetAdminBadgeAddress: '',
32-
faucetCreationTxHash: '',
33-
34-
lendingMarketCreationTxHash: '',
35-
lendingMarketComponentAddress: '',
36-
lendingMarketAdminBadgeAddress: '',
37-
})
38-
3927
export const default_asset_list: PoolInfo[] = [
40-
{
41-
resource_address: XRD,
42-
symbol: 'XRD',
43-
name: 'Radix',
44-
icon: 'https://s2.coinmarketcap.com/static/img/coins/64x64/11948.png',
45-
initial_price: 250,
46-
liquidation_threshold: 0.7,
47-
liquidation_closing_factor: 0.5,
48-
liquidation_spread: 0.05,
49-
flashloan_fee_rate: 0.05
50-
},
28+
// {
29+
// resource_address: XRD,
30+
// symbol: 'XRD',
31+
// name: 'Radix',
32+
// icon: 'https://s2.coinmarketcap.com/static/img/coins/64x64/11948.png',
33+
// initial_price: 250,
34+
// liquidation_threshold: 0.7,
35+
// liquidation_closing_factor: 0.5,
36+
// liquidation_spread: 0.05,
37+
// flashloan_fee_rate: 0.05
38+
// },
5139
{
5240
symbol: 'BTC',
5341
name: 'Bitcoin',

7-defi-devpost/kl_protocol/frontend/src/lib/api/rdt.ts

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { load_faucet_state, load_manager_pool_state } from '$lib/state/pool_state';
1+
import { loan_user_resources } from '$lib/state/account';
2+
import { dapp_state } from '$lib/state/dapp';
3+
import { load_manager_pool_state, } from '$lib/state/lending_pool_manager';
24
import {
35
StateApi,
46
StatusApi,
@@ -7,7 +9,6 @@ import {
79
} from '@radixdlt/babylon-gateway-api-sdk';
810
import { RadixDappToolkit } from "@radixdlt/radix-dapp-toolkit";
911
import { get } from 'svelte/store';
10-
import { dapp_data } from '../data';
1112

1213

1314
export const dAppId = 'account_tdx_b_1pqwzpeqv8mph3u80g5zch24gtpky3wy3demlg6ta6q4qhkdpd8'
@@ -29,14 +30,17 @@ export const rdt = RadixDappToolkit(
2930
}).map(({ data: { accounts } }) => {
3031
console.log(accounts)
3132
if (accounts == undefined) return
32-
dapp_data.set({ ...get(dapp_data), accountAddress: (accounts.length >= 1 ? accounts[0].address : '') })
33+
dapp_state.set({ ...get(dapp_state), accountAddress: (accounts.length >= 1 ? accounts[0].address : '') })
3334

35+
update_dapp_state(0)
3436
});
37+
38+
3539
},
3640
{
3741
networkId: 11,
3842
onDisconnect: () => {
39-
dapp_data.set({ ...get(dapp_data), accountAddress: '' })
43+
dapp_state.set({ ...get(dapp_state), accountAddress: '' })
4044
},
4145
onInit: async (data) => {
4246

@@ -45,18 +49,20 @@ export const rdt = RadixDappToolkit(
4549
let accounts = data.accounts
4650

4751
if (accounts == undefined || accounts.length === 0) {
48-
dapp_data.set({ ...get(dapp_data), accountAddress: '' })
52+
dapp_state.set({ ...get(dapp_state), accountAddress: '' })
4953
} else {
50-
dapp_data.set({ ...get(dapp_data), accountAddress: (accounts.length >= 1 ? accounts[0].address : '') })
51-
52-
let state = await stateApi.entityResources({ entityResourcesRequest: { address: accounts[0].address } })
53-
54-
console.log(state)
55-
56-
await load_faucet_state()
57-
await load_manager_pool_state()
54+
dapp_state.set({ ...get(dapp_state), accountAddress: (accounts.length >= 1 ? accounts[0].address : '') })
5855
}
5956

57+
update_dapp_state(0)
6058
}
6159
}
6260
);
61+
62+
63+
export function update_dapp_state(waiting_time = 1000) {
64+
setTimeout(async () => {
65+
await load_manager_pool_state()
66+
await loan_user_resources()
67+
}, waiting_time);
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { openModal, closeModal } from "svelte-modals";
2+
import { rdt, update_dapp_state } from "./api/rdt";
3+
4+
5+
import Modal1 from '$lib/modals/Modal1.svelte';
6+
import NumberInputModal from '$lib/modals/NumberInputModal.svelte';
7+
import type { ManifestBuilder } from "@radixdlt/radix-dapp-toolkit";
8+
9+
10+
export async function send_transaction(txManifest: ManifestBuilder) {//, callback: Function = async () => undefined) {
11+
openModal(Modal1, { title: '' });
12+
13+
let transactionManifest = txManifest.build().toString()
14+
15+
console.log(transactionManifest)
16+
17+
let result = await rdt.sendTransaction({
18+
transactionManifest,
19+
version: 1
20+
});
21+
22+
console.log(result)
23+
24+
if (result.isErr()) {
25+
26+
closeModal();
27+
28+
29+
throw result.error
30+
///
31+
} else {
32+
33+
}
34+
35+
closeModal();
36+
37+
window.location.reload();
38+
39+
update_dapp_state()
40+
41+
// return result
42+
}
43+
44+
45+
export async function get_number_input(
46+
{ title, min, max, onSubmit }
47+
: { title: string; min: number; max: number; onSubmit: (input: number) => any; }
48+
) {
49+
openModal(NumberInputModal, {
50+
title,
51+
min, max,
52+
onclick: onSubmit,
53+
});
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script lang="ts">
2+
import { format_number } from '$lib/utils';
3+
import { Group, Text, type SvelteUINumberSize } from '@svelteuidev/core';
4+
5+
// export let market: PoolState;
6+
// export let cdp_id: string;
7+
8+
export let label: string;
9+
export let amount: number;
10+
export let price: number = 0;
11+
export let size: SvelteUINumberSize = 'sm';
12+
export let price_size: SvelteUINumberSize = 'xs';
13+
export let percent = false;
14+
export let short = false;
15+
</script>
16+
17+
<Group position="center" noWrap spacing="xs">
18+
<Text {size}>{label} :</Text>
19+
20+
{#if !percent}
21+
<Text {size} weight={'bold'}>{format_number(amount, short ? 'compact' : undefined)}</Text>
22+
{#if price != 0}
23+
<Text size={price_size}
24+
>(${format_number(price * amount, short ? 'compact' : undefined)})</Text
25+
>
26+
{/if}
27+
{:else}
28+
<Text {size} weight={'bold'}>{format_number(amount * 100, undefined)} %</Text>
29+
<!-- else content here -->
30+
{/if}
31+
</Group>

7-defi-devpost/kl_protocol/frontend/src/lib/components/LendingMarket.svelte

-58
This file was deleted.

7-defi-devpost/kl_protocol/frontend/src/lib/components/LendingPoolText.svelte

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
22
import { Card, Container, Group, Space, Text, Image } from '@svelteuidev/core';
3-
import type { PoolInfo } from '../models';
43
54
export let name: string;
65
export let value: number | undefined;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script lang="ts">
2+
import { Loader, Modal } from '@svelteuidev/core';
3+
import { closeModal } from 'svelte-modals';
4+
5+
// provided by <Modals />
6+
export let isOpen: boolean;
7+
8+
export let title: string;
9+
// export let message: string;
10+
</script>
11+
12+
{#if isOpen}
13+
<Modal centered opened={isOpen} withCloseButton={false} size="xs" {title}>
14+
<Loader size="lg" />
15+
</Modal>
16+
{/if}

0 commit comments

Comments
 (0)