Skip to content
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

feat: new testnet deployment #2

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@ The Sway Lend alive on [https://swaylend.com](https://swaylend.com)
>Please note that Sway Lend is in the alpha testing phase and contracts may change in the future, leading to potential loss of supply/borrow amount.
---



```
FUEL TESTNET

Oracle contract = 0x1f6a416e814dd5adf97b994f1eb5b6d694f91bfafdc75686f1f7ed64b760332c
Pyth Oracle contract = 0x73591bf32f010ce4e83d86005c24e7833b397be38014ab670a73f6fde59ad607

Token factory contract = 0x4069ff37aa31cc75849c78c6e92a92d01499c22e2ae922cfa9c311a845c7de63
Token factory contract = 0xb2cb14cba2bb4bf4e565d8e0fbd6695df055b4ac25607962a827a72ae8622f5e

Market contract = 0x91240c4837da1d27b4fc4d3f498fd4b92b1e782ace1c6e22622a27ae635c3a76
Market contract = 0xc574a39aba9d9311df8f07b4d4805ab6b19f64d8364ef1498c73509220985f56

SWAY = 0x65c7f292870616c43cdc02b1959eaae62cb718b637327fb3463e3e9f25616e9c
ETH = 0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07
USDC = 0x403489ee55a733cce6deb3e46e16a0ded38f902ff70224df97e15c243319b6f3
LINK = 0x65f1449bfcc69fd4bd7b90d9fde52cde32268581bc81ccb6a34c0a2f9b2ab947
UNI = 0x3a6d9fd36c8caaf6de9723c399a71c0c183577781d90027f023883dc945cb168
BTC = 0xb3a405892c0725ae9cfc117306752f623e3f357963b7489636b83d4842f96d62
COMP = 0xc05e8d231cba888ee92bd6c8825413ba494c3d623b0cd7b1fc96d72f159c6806
USDC = 0x23e8c3a2fc7a10cfa612da898d1cb3c0f0bb2a94de29ec4fa742bd2f690d9a67
UNI = 0x7a31611c81e974db193570a6b918d083cbf223ddfef0cce18e02746b21ea8964
BTC = 0x7d9d3e3df2900080f47b5e55c0501e153d21e67a2cdf86cb86ff5b717daab767
```

---
Expand Down
6 changes: 3 additions & 3 deletions apps/indexer/config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: Fuel Greeter Indexer
networks:
- id: 0
start_block: 6421040
start_block: 7208668
contracts:
- name: Market
address: 0xbf31f1750f5afaf3ac356ab0b922c702cbd766a4ca878c5e7f3876cc4d608577
address: 0xc574a39aba9d9311df8f07b4d4805ab6b19f64d8364ef1498c73509220985f56
abi_file_path: ../../contracts/market/out/release/market-abi.json
handler: ./src/EventHandlers.ts
events:
- name: CollateralAssetAdded
# - name: CollateralAssetUpdated
- name: CollateralAssetUpdated
- name: CollateralAssetPaused
- name: CollateralAssetResumed
- name: UserBasicEvent
Expand Down
22 changes: 22 additions & 0 deletions apps/indexer/src/EventHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ Market.CollateralAssetAdded.handler(async ({ event, context }) => {
});
});

// Update collateral asset
Market.CollateralAssetUpdated.loader(({ event, context }) => {
const assetId = event.data.asset_id;
context.CollateralAsset.load(assetId);
});

Market.CollateralAssetUpdated.handler(async ({ event, context }) => {
const assetId = event.data.asset_id;

context.CollateralAsset.set({
id: assetId,
priceFeedId: event.data.configuration.price_feed_id,
decimals: event.data.configuration.decimals,
borrowCollateralFactor: event.data.configuration.borrow_collateral_factor,
liquidateCollateralFactor:
event.data.configuration.liquidate_collateral_factor,
liquidationPenalty: event.data.configuration.liquidation_penalty,
supplyCap: event.data.configuration.supply_cap,
paused: event.data.configuration.paused,
});
});

// Pause Collateral Asset
Market.CollateralAssetPaused.loader(({ event, context }) => {
const assetId = event.data.asset_id;
Expand Down
63 changes: 52 additions & 11 deletions apps/indexer/test/tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const BOB_ADDRESS = Addresses.mockAddresses[2];

describe('Market contract event tests', () => {
describe('CollateralAsset events', async () => {
it('CollateralAssetAdded -> CollateralAssetPaused -> CollateralAssetResumed', async () => {
it('CollateralAssetAdded -> CollateralAssetUpdated -> CollateralAssetPaused -> CollateralAssetResumed', async () => {
// Initializing the mock database
const mockDbInitial = MockDb.createMockDb();

Expand Down Expand Up @@ -75,6 +75,47 @@ describe('Market contract event tests', () => {
// Asserting that the entity in the mock database is the same as the expected entity
assert.deepEqual(expectedCollateralAsset, actualCollateralAsset);

// Creating a mock collateral asset updated event
const mockCollateralAssetUpdatedEvent =
Market.CollateralAssetUpdated.mockData({
asset_id: assetId,
configuration: {
asset_id: assetId,
price_feed_id: TEST_PRICE_FEED_ID,
decimals: 1,
borrow_collateral_factor: BigInt(2),
liquidate_collateral_factor: BigInt(3),
liquidation_penalty: BigInt(4),
supply_cap: BigInt(5),
paused: false,
},
});

// Processing the mock event on the mock database
updatedMockDb = await Market.CollateralAssetUpdated.processEvent({
event: mockCollateralAssetUpdatedEvent,
mockDb: updatedMockDb,
});

// Expected entity that should be created
expectedCollateralAsset = {
id: assetId,
priceFeedId: TEST_PRICE_FEED_ID,
decimals: 1,
borrowCollateralFactor: BigInt(2),
liquidateCollateralFactor: BigInt(3),
liquidationPenalty: BigInt(4),
supplyCap: BigInt(5),
paused: false,
};

// Getting the entity from the mock database
actualCollateralAsset =
updatedMockDb.entities.CollateralAsset.get(assetId);

// Asserting that the entity in the mock database is the same as the expected entity
assert.deepEqual(expectedCollateralAsset, actualCollateralAsset);

// Creating a mock collateral asset paused event
const mockCollateralAssetPausedEvent =
Market.CollateralAssetPaused.mockData({
Expand All @@ -91,11 +132,11 @@ describe('Market contract event tests', () => {
expectedCollateralAsset = {
id: assetId,
priceFeedId: TEST_PRICE_FEED_ID,
decimals: 0,
borrowCollateralFactor: BigInt(0),
liquidateCollateralFactor: BigInt(0),
liquidationPenalty: BigInt(0),
supplyCap: BigInt(0),
decimals: 1,
borrowCollateralFactor: BigInt(2),
liquidateCollateralFactor: BigInt(3),
liquidationPenalty: BigInt(4),
supplyCap: BigInt(5),
paused: true,
};

Expand All @@ -122,11 +163,11 @@ describe('Market contract event tests', () => {
expectedCollateralAsset = {
id: assetId,
priceFeedId: TEST_PRICE_FEED_ID,
decimals: 0,
borrowCollateralFactor: BigInt(0),
liquidateCollateralFactor: BigInt(0),
liquidationPenalty: BigInt(0),
supplyCap: BigInt(0),
decimals: 1,
borrowCollateralFactor: BigInt(2),
liquidateCollateralFactor: BigInt(3),
liquidationPenalty: BigInt(4),
supplyCap: BigInt(5),
paused: false,
};

Expand Down
7 changes: 5 additions & 2 deletions apps/oracle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ async fn main() {

let mut message = String::new();
if update_result.is_ok() {
message += format!("\n-----------------------------------\n").as_str();
message += format!("✅ Prices updated\n").as_str();
message += format!("⛽️ Gas used: {}\n", update_result.unwrap().gas_used).as_str();
message += format!(
Expand All @@ -75,14 +76,16 @@ async fn main() {
/ 10f64.powf(9f64)
)
.as_str();
message += format!("-----------------------------------\n\n").as_str();
message += format!("-----------------------------------\n").as_str();
} else {
message += format!("\n-----------------------------------\n").as_str();
message += format!("❌ Prices not updated\n").as_str();
message += format!("Error: {}\n", update_result.unwrap_err()).as_str();
message += format!("-----------------------------------\n").as_str();
}

println!("{message}");

sleep(Duration::from_secs(5 * 60));
sleep(Duration::from_secs(30));
}
}
2 changes: 1 addition & 1 deletion contracts/market/tests/scripts/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn deploy() {

//--------------- Tokens ---------------
let tokens_json_path =
PathBuf::from(env!("CARGO_WORKSPACE_DIR")).join("libs/token_sdk/tokens.json");
PathBuf::from(env!("CARGO_WORKSPACE_DIR")).join("libs/token_sdk/tokens.testnet.json");
let tokens_path_str = tokens_json_path.to_str().unwrap();

let token_contract = TokenContract::new(token_id, wallet.clone()).await;
Expand Down
2 changes: 1 addition & 1 deletion contracts/market/tests/scripts/mint_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async fn mint() {
let token_contract = TokenContract::new(token_contract_id, wallet.clone()).await;

let tokens_json_path =
PathBuf::from(env!("CARGO_WORKSPACE_DIR")).join("libs/token_sdk/tokens.json");
PathBuf::from(env!("CARGO_WORKSPACE_DIR")).join("libs/token_sdk/tokens.testnet.json");
let tokens_path_str = tokens_json_path.to_str().unwrap();

let (assets, _) = token_contract.load_tokens(tokens_path_str, &wallet).await;
Expand Down
1 change: 0 additions & 1 deletion libs/market_sdk/src/market_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ impl MarketContract {
.await?
};

// TODO[Martin]: Revisting this clone
let market = Market::new(id.clone(), wallet.clone());

Ok(Self { instance: market })
Expand Down
6 changes: 3 additions & 3 deletions libs/token_sdk/tokens.testnet.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"asset_id": "0x403489ee55a733cce6deb3e46e16a0ded38f902ff70224df97e15c243319b6f3",
"asset_id": "0x23e8c3a2fc7a10cfa612da898d1cb3c0f0bb2a94de29ec4fa742bd2f690d9a67",
"price_feed_id": "0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
"price_feed_decimals": 7,
"name": "USD Coin",
Expand All @@ -24,7 +24,7 @@
"supply_cap": 2000000000000000000000
},
{
"asset_id": "0xb3a405892c0725ae9cfc117306752f623e3f357963b7489636b83d4842f96d62",
"asset_id": "0x7d9d3e3df2900080f47b5e55c0501e153d21e67a2cdf86cb86ff5b717daab767",
"price_feed_id": "0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",
"price_feed_decimals": 7,
"name": "Bitcoin",
Expand All @@ -38,7 +38,7 @@
"supply_cap": 1000000000000000000000
},
{
"asset_id": "0x3a6d9fd36c8caaf6de9723c399a71c0c183577781d90027f023883dc945cb168",
"asset_id": "0x7a31611c81e974db193570a6b918d083cbf223ddfef0cce18e02746b21ea8964",
"price_feed_id": "0x78d185a741d07edb3412b09008b7c5cfb9bbbd7d568bf00ba737b456ba171501",
"price_feed_decimals": 8,
"name": "Uniswap",
Expand Down
Loading