File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed
app/src/features/editor/examples/sway Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { ExampleMenuItem } from "../../components/ExampleDropdown" ;
2
2
import { EXAMPLE_SWAY_CONTRACT_COUNTER } from "./counter" ;
3
+ import { EXAMPLE_SWAY_CONTRACT_LIQUIDITY_POOL } from "./liquiditypool" ;
3
4
import { EXAMPLE_SWAY_CONTRACT_SINGLEASSET } from "./singleasset" ;
4
5
import { EXAMPLE_SWAY_CONTRACT_MULTIASSET } from "./multiasset" ;
5
6
6
7
export const EXAMPLE_SWAY_CONTRACTS : ExampleMenuItem [ ] = [
7
8
{ label : "Counter.sw" , code : EXAMPLE_SWAY_CONTRACT_COUNTER } ,
9
+ { label : "LiquidityPool.sw" , code : EXAMPLE_SWAY_CONTRACT_LIQUIDITY_POOL } ,
8
10
{ label : "SingleAsset.sw" , code : EXAMPLE_SWAY_CONTRACT_SINGLEASSET } ,
9
11
{ label : "MultiAsset.sw" , code : EXAMPLE_SWAY_CONTRACT_MULTIASSET } ,
10
12
] ;
Original file line number Diff line number Diff line change
1
+ export const EXAMPLE_SWAY_CONTRACT_LIQUIDITY_POOL = `contract;
2
+
3
+ use std::{
4
+ asset::{
5
+ mint_to,
6
+ transfer,
7
+ },
8
+ call_frames::msg_asset_id,
9
+ constants::DEFAULT_SUB_ID,
10
+ context::msg_amount
11
+ };
12
+
13
+ abi LiquidityPool {
14
+ fn deposit(recipient: Address);
15
+ fn withdraw(recipient: Address);
16
+ }
17
+
18
+ const BASE_ASSET: AssetId = AssetId::from(0x9ae5b658754e096e4d681c548daf46354495a437cc61492599e33fc64dcdc30c);
19
+
20
+ impl LiquidityPool for Contract {
21
+ fn deposit(recipient: Address) {
22
+ assert(msg_asset_id() == BASE_ASSET);
23
+ assert(msg_amount() > 0);
24
+
25
+ // Mint two times the amount.
26
+ let amount_to_mint = msg_amount() * 2;
27
+
28
+ // Mint some LP assets based upon the amount of the base asset.
29
+ mint_to(Identity::Address(recipient), DEFAULT_SUB_ID, amount_to_mint);
30
+ }
31
+
32
+ fn withdraw(recipient: Address) {
33
+ let asset_id = AssetId::default();
34
+ assert(msg_asset_id() == asset_id);
35
+ assert(msg_amount() > 0);
36
+
37
+ // Amount to withdraw.
38
+ let amount_to_transfer = msg_amount() / 2;
39
+
40
+ // Transfer base asset to recipient.
41
+ transfer(Identity::Address(recipient), BASE_ASSET, amount_to_transfer);
42
+ }
43
+ }` ;
Original file line number Diff line number Diff line change @@ -6,4 +6,4 @@ name = "swaypad"
6
6
7
7
[dependencies ]
8
8
standards = { git = " https://github.com/FuelLabs/sway-standards" , tag = " v0.7.0" }
9
- sway_libs = { git = " https://github.com/FuelLabs/sway-libs" , tag = " v0.25.1 " }
9
+ sway_libs = { git = " https://github.com/FuelLabs/sway-libs" , tag = " v0.25.2 " }
You can’t perform that action at this time.
0 commit comments