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

Map env bug #225

Merged
merged 5 commits into from
May 1, 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
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Stellar Expert WASM Release
on:
push:
tags:
- 'v*' # triggered whenever a new tag (previxed with "v") is pushed to the repository
jobs:
release-contract-backstop:
uses: stellar-expert/soroban-build-workflow/.github/workflows/release.yml@main
with:
release_name: ${{ github.ref_name }}
release_description: 'Blend Backstop Release'
package: 'backstop'
make_target: 'build'
secrets:
release_token: ${{ secrets.GITHUB_TOKEN }}

release-contract-pool:
uses: stellar-expert/soroban-build-workflow/.github/workflows/release.yml@main
with:
release_name: ${{ github.ref_name }}
release_description: 'Blend Pool Release'
package: 'pool'
make_target: 'build'
secrets:
release_token: ${{ secrets.GITHUB_TOKEN }}

release-contract-emitter:
uses: stellar-expert/soroban-build-workflow/.github/workflows/release.yml@main
with:
release_name: ${{ github.ref_name }}
release_description: 'Blend Emitter Release'
package: 'emitter'
secrets:
release_token: ${{ secrets.GITHUB_TOKEN }}

release-contract-pool-factory:
uses: stellar-expert/soroban-build-workflow/.github/workflows/release.yml@main
with:
release_name: ${{ github.ref_name }}
release_description: 'Blend Pool Factory Release'
package: 'pool-factory'
make_target: 'build'
secrets:
release_token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 36 additions & 4 deletions backstop/src/backstop/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ pub struct PoolBackstopData {

pub fn load_pool_backstop_data(e: &Env, address: &Address) -> PoolBackstopData {
let pool_balance = storage::get_pool_balance(e, address);
let q4w_pct = pool_balance
.q4w
.fixed_div_ceil(pool_balance.shares, SCALAR_7)
.unwrap_optimized();
let q4w_pct = if pool_balance.shares > 0 {
pool_balance
.q4w
.fixed_div_ceil(pool_balance.shares, SCALAR_7)
.unwrap_optimized()
} else {
0
};

let (blnd_per_tkn, usdc_per_tkn) = storage::get_lp_token_val(e);
let blnd = pool_balance
Expand Down Expand Up @@ -202,6 +206,34 @@ mod tests {
});
}

#[test]
fn test_load_pool_data_no_shares() {
let e = Env::default();

let backstop_address = create_backstop(&e);
let pool = Address::generate(&e);

e.as_contract(&backstop_address, || {
storage::set_pool_balance(
&e,
&pool,
&PoolBalance {
shares: 0,
tokens: 250_0000000,
q4w: 0,
},
);
storage::set_lp_token_val(&e, &(5_0000000, 0_0500000));

let pool_data = load_pool_backstop_data(&e, &pool);

assert_eq!(pool_data.tokens, 250_0000000);
assert_eq!(pool_data.q4w_pct, 0);
assert_eq!(pool_data.blnd, 1_250_0000000);
assert_eq!(pool_data.usdc, 12_5000000);
});
}

/********** require_is_from_pool_factory **********/

#[test]
Expand Down
6 changes: 3 additions & 3 deletions backstop/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
storage,
};
use soroban_sdk::{
contract, contractclient, contractimpl, panic_with_error, Address, Env, Map, Symbol, Vec,
contract, contractclient, contractimpl, panic_with_error, Address, Env, Symbol, Vec,
};

/// ### Backstop
Expand Down Expand Up @@ -38,7 +38,7 @@ pub trait Backstop {
blnd_token: Address,
usdc_token: Address,
pool_factory: Address,
drop_list: Map<Address, i128>,
drop_list: Vec<(Address, i128)>,
);

/********** Core **********/
Expand Down Expand Up @@ -184,7 +184,7 @@ impl Backstop for BackstopContract {
usdc_token: Address,
blnd_token: Address,
pool_factory: Address,
drop_list: Map<Address, i128>,
drop_list: Vec<(Address, i128)>,
) {
storage::extend_instance(&e);
if storage::get_is_init(&e) {
Expand Down
3 changes: 2 additions & 1 deletion backstop/src/dependencies/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pub use pool_factory::Client as PoolFactoryClient;

mod comet;
pub use comet::Client as CometClient;
#[cfg(any(test, feature = "testutils"))]

#[cfg(test)]
pub use comet::WASM as COMET_WASM;

mod emitter;
Expand Down
54 changes: 27 additions & 27 deletions backstop/src/emissions/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ mod tests {
assert_eq!(result, 75_3145677 + 6_2904190);
assert_eq!(
lp_client.balance(&backstop_address),
backstop_lp_balance + 6_5244800
backstop_lp_balance + 6_4729326
);
assert_eq!(
blnd_token_client.balance(&backstop_address),
Expand All @@ -221,18 +221,18 @@ mod tests {
let sam_balance_1 = storage::get_user_balance(&e, &pool_1_id, &samwise);
assert_eq!(sam_balance_1.shares, 9_0000000);
let frodo_balance_1 = storage::get_user_balance(&e, &pool_1_id, &frodo);
assert_eq!(frodo_balance_1.shares, pre_frodo_balance_1 + 4_5761820);
assert_eq!(frodo_balance_1.shares, pre_frodo_balance_1 + 4_5400274);
let sam_balance_2 = storage::get_user_balance(&e, &pool_2_id, &samwise);
assert_eq!(sam_balance_2.shares, 7_5000000);
let frodo_balance_2 = storage::get_user_balance(&e, &pool_2_id, &frodo);
assert_eq!(frodo_balance_2.shares, pre_frodo_balance_2 + 0_3947102);
assert_eq!(frodo_balance_2.shares, pre_frodo_balance_2 + 0_3915917);

let pool_balance_1 = storage::get_pool_balance(&e, &pool_1_id);
assert_eq!(pool_balance_1.tokens, pre_pool_tokens_1 + 6_1015761);
assert_eq!(pool_balance_1.shares, pre_pool_shares_1 + 4_5761820);
assert_eq!(pool_balance_1.tokens, pre_pool_tokens_1 + 6_0533699);
assert_eq!(pool_balance_1.shares, pre_pool_shares_1 + 4_5400274);
let pool_balance_2 = storage::get_pool_balance(&e, &pool_2_id);
assert_eq!(pool_balance_2.tokens, pre_pool_tokens_2 + 0_4229038);
assert_eq!(pool_balance_2.shares, pre_pool_shares_2 + 0_3947102);
assert_eq!(pool_balance_2.tokens, pre_pool_tokens_2 + 0_4195626);
assert_eq!(pool_balance_2.shares, pre_pool_shares_2 + 0_3915917);

let new_backstop_1_data =
storage::get_backstop_emis_data(&e, &pool_1_id).unwrap_optimized();
Expand Down Expand Up @@ -371,7 +371,7 @@ mod tests {
assert_eq!(result, 75_3145677 + 6_2904190);
assert_eq!(
lp_client.balance(&backstop_address),
backstop_lp_balance + 6_5244800
backstop_lp_balance + 6_4729326
);
assert_eq!(
blnd_token_client.balance(&backstop_address),
Expand All @@ -380,18 +380,18 @@ mod tests {
let sam_balance_1 = storage::get_user_balance(&e, &pool_1_id, &samwise);
assert_eq!(sam_balance_1.shares, 9_0000000);
let frodo_balance_1 = storage::get_user_balance(&e, &pool_1_id, &frodo);
assert_eq!(frodo_balance_1.shares, pre_frodo_balance_1 + 4_5761820);
assert_eq!(frodo_balance_1.shares, pre_frodo_balance_1 + 4_5400274);
let sam_balance_2 = storage::get_user_balance(&e, &pool_2_id, &samwise);
assert_eq!(sam_balance_2.shares, 7_5000000);
let frodo_balance_2 = storage::get_user_balance(&e, &pool_2_id, &frodo);
assert_eq!(frodo_balance_2.shares, pre_frodo_balance_2 + 0_3947102);
assert_eq!(frodo_balance_2.shares, pre_frodo_balance_2 + 0_3915917);

let pool_balance_1 = storage::get_pool_balance(&e, &pool_1_id);
assert_eq!(pool_balance_1.tokens, pre_pool_tokens_1 + 6_1015761);
assert_eq!(pool_balance_1.shares, pre_pool_shares_1 + 4_5761820);
assert_eq!(pool_balance_1.tokens, pre_pool_tokens_1 + 6_0533699);
assert_eq!(pool_balance_1.shares, pre_pool_shares_1 + 4_5400274);
let pool_balance_2 = storage::get_pool_balance(&e, &pool_2_id);
assert_eq!(pool_balance_2.tokens, pre_pool_tokens_2 + 0_4229038);
assert_eq!(pool_balance_2.shares, pre_pool_shares_2 + 0_3947102);
assert_eq!(pool_balance_2.tokens, pre_pool_tokens_2 + 0_4195626);
assert_eq!(pool_balance_2.shares, pre_pool_shares_2 + 0_3915917);

let new_backstop_1_data =
storage::get_backstop_emis_data(&e, &pool_1_id).unwrap_optimized();
Expand Down Expand Up @@ -435,47 +435,47 @@ mod tests {
&vec![&e, pool_1_id.clone(), pool_2_id.clone()],
&frodo,
);
assert_eq!(result_1, 1005009202);
assert_eq!(result_1, 1005194703);
assert_eq!(
blnd_token_client.balance(&backstop_address),
200_0000000 - (75_3145677 + 6_2904190) - (1005009202)
200_0000000 - (75_3145677 + 6_2904190) - (1005194703)
);
assert_eq!(
lp_client.balance(&backstop_address),
backstop_lp_balance + 7_9137036
backstop_lp_balance + 7_7889107
);
let sam_balance_1 = storage::get_user_balance(&e, &pool_1_id, &samwise);
assert_eq!(sam_balance_1.shares, 9_0000000);
let frodo_balance_1 = storage::get_user_balance(&e, &pool_1_id, &frodo);
assert_eq!(frodo_balance_1.shares, pre_frodo_balance_1 + 4_3004891);
assert_eq!(frodo_balance_1.shares, pre_frodo_balance_1 + 4_2609092);
let sam_balance_2 = storage::get_user_balance(&e, &pool_2_id, &samwise);
assert_eq!(sam_balance_2.shares, 7_5000000);
let frodo_balance_2 = storage::get_user_balance(&e, &pool_2_id, &frodo);
assert_eq!(frodo_balance_2.shares, pre_frodo_balance_2 + 2_0344033);
assert_eq!(frodo_balance_2.shares, pre_frodo_balance_2 + 2_0152958);

let pool_balance_1 = storage::get_pool_balance(&e, &pool_1_id);
assert_eq!(pool_balance_1.tokens, pre_pool_tokens_1 + 5_7339856);
assert_eq!(pool_balance_1.shares, pre_pool_shares_1 + 4_3004891);
assert_eq!(pool_balance_1.tokens, pre_pool_tokens_1 + 5_6812124);
assert_eq!(pool_balance_1.shares, pre_pool_shares_1 + 4_2609092);
let pool_balance_2 = storage::get_pool_balance(&e, &pool_2_id);
assert_eq!(pool_balance_2.tokens, pre_pool_tokens_2 + 2_1797179);
assert_eq!(pool_balance_2.shares, pre_pool_shares_2 + 2_0344033);
assert_eq!(pool_balance_2.tokens, pre_pool_tokens_2 + 2_1592456);
assert_eq!(pool_balance_2.shares, pre_pool_shares_2 + 2_0152958);
let new_backstop_1_data =
storage::get_backstop_emis_data(&e, &pool_1_id).unwrap_optimized();
let new_user_1_data =
storage::get_user_emis_data(&e, &pool_1_id, &samwise).unwrap_optimized();
assert_eq!(new_backstop_1_data.last_time, block_timestamp_1);
assert_eq!(new_backstop_1_data.index, 164344784);
assert_eq!(new_backstop_1_data.index, 164363961);
assert_eq!(new_user_1_data.accrued, 0);
assert_eq!(new_user_1_data.index, 164344784);
assert_eq!(new_user_1_data.index, 164363961);

let new_backstop_2_data =
storage::get_backstop_emis_data(&e, &pool_2_id).unwrap_optimized();
let new_user_2_data =
storage::get_user_emis_data(&e, &pool_2_id, &samwise).unwrap_optimized();
assert_eq!(new_backstop_2_data.last_time, block_timestamp_1);
assert_eq!(new_backstop_2_data.index, 43961378);
assert_eq!(new_backstop_2_data.index, 43963099);
assert_eq!(new_user_2_data.accrued, 0);
assert_eq!(new_user_2_data.index, 43961378);
assert_eq!(new_user_2_data.index, 43963099);
});
}

Expand Down
11 changes: 5 additions & 6 deletions backstop/src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use soroban_sdk::{
contracttype, unwrap::UnwrapOptimized, vec, Address, Env, IntoVal, Map, Symbol, TryFromVal,
Val, Vec,
contracttype, unwrap::UnwrapOptimized, vec, Address, Env, IntoVal, Symbol, TryFromVal, Val, Vec,
};

use crate::backstop::{PoolBalance, UserBalance};
Expand Down Expand Up @@ -466,21 +465,21 @@ pub fn set_user_emis_data(
/********** Drop Emissions **********/

/// Get the current pool addresses that are in the drop list and the amount of the initial distribution they receive
pub fn get_drop_list(e: &Env) -> Map<Address, i128> {
pub fn get_drop_list(e: &Env) -> Vec<(Address, i128)> {
e.storage()
.temporary()
.get::<Symbol, Map<Address, i128>>(&Symbol::new(&e, DROP_LIST_KEY))
.get::<Symbol, Vec<(Address, i128)>>(&Symbol::new(&e, DROP_LIST_KEY))
.unwrap_optimized()
}

/// Set the drop list
///
/// ### Arguments
/// * `drop_list` - The map of pool addresses to the amount of the initial distribution they receive
pub fn set_drop_list(e: &Env, drop_list: &Map<Address, i128>) {
pub fn set_drop_list(e: &Env, drop_list: &Vec<(Address, i128)>) {
e.storage()
.temporary()
.set::<Symbol, Map<Address, i128>>(&Symbol::new(&e, DROP_LIST_KEY), drop_list);
.set::<Symbol, Vec<(Address, i128)>>(&Symbol::new(&e, DROP_LIST_KEY), drop_list);
e.storage().temporary().extend_ttl(
&Symbol::new(&e, DROP_LIST_KEY),
LEDGER_THRESHOLD_USER,
Expand Down
14 changes: 4 additions & 10 deletions backstop/src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,15 @@ pub(crate) fn create_comet_lp_pool<'a>(
let usdc_client = MockTokenClient::new(e, usdc_token);
blnd_client.mint(&admin, &1_000_0000000);
usdc_client.mint(&admin, &25_0000000);
let exp_ledger = e.ledger().sequence() + 100;
blnd_client.approve(&admin, &contract_address, &2_000_0000000, &exp_ledger);
usdc_client.approve(&admin, &contract_address, &2_000_0000000, &exp_ledger);

client.init(&Address::generate(e), &admin);
client.bundle_bind(
client.init(
admin,
&vec![e, blnd_token.clone(), usdc_token.clone()],
&vec![e, 0_8000000, 0_2000000],
&vec![e, 1_000_0000000, 25_0000000],
&vec![e, 8_0000000, 2_0000000],
&0_0030000,
);

client.set_swap_fee(&0_0030000, &admin);
client.set_public_swap(&admin, &true);
client.finalize();

(contract_address, client)
}

Expand Down
2 changes: 1 addition & 1 deletion blend-contract-sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blend-contract-sdk"
version = "0.2.0"
version = "1.0.0"
description = "Traits, clients, types, and WASMs for the Blend Protocol for use in Soroban contract development."
homepage = "https://github.com/blend-capital/blend-contracts"
repository = "https://github.com/blend-capital/blend-contracts"
Expand Down
21 changes: 6 additions & 15 deletions blend-contract-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,12 @@ pool_client.mock_all_auths().update_status(); // update status based on backstop

## WASM Verification

The WASM files included will align with the GitHub release the SDK was published with (the version numbers will match). The WASM files were generated with the Makefile.
The WASM files included will align with the GitHub release the SDK was published with (the version numbers will match).

Since WASM builds can vary based on factors like OS, here are the details of the machine that built the WASMs included in this package:

* Ubuntu 22.04.4 LTS
* stable-x86_64-unknown-linux-gnu (default)
* rustc 1.77.1 (7cf61ebde 2024-03-27)
* soroban 20.3.1 (ae5446f63ca8a275e61912019199254d598f3bd5)
* soroban-env 20.2.1 (18a10592853d9edf4e341b565b0b1638f95f0393)
* soroban-env interface version 85899345920
* stellar-xdr 20.1.0 (8b9d623ef40423a8462442b86997155f2c04d3a1)
* xdr curr (b96148cd4acc372cc9af17b909ffe4b12c43ecb6)
The WASMs are generated with the [Stellar Expert WASM Release Action](https://github.com/stellar-expert/soroban-build-workflow)

The SHA256 Checksums:
* backstop - `8dfbc6ba300cde6ebe747cf985cf9221bf3594981595b9c26bbd108ff19a5598`
* emitter - `b1555702a4cca7c44e02beb5aa82b0271c0367471c68f2ec9246c31b202e38ee`
* pool_factory - `8bc7894d8a4e46b085d0579e233e3c436bb34e18f9a2a83d4bde8526cde18cb6`
* pool - `76ebcea354d5959c5b0d38818ddf1524c5af16970231b532f5caa63121930861`
* backstop - `62f61b32fff99f7eec052a8e573c367759f161c481a5caf0e76a10ae4617c3b4`
* emitter - `438a5528cff17ede6fe515f095c43c5f15727af17d006971485e52462e7e7b89`
* pool_factory - `0287f4ad7350935b83d94e046c0bcabc960b233dbce1531008c021b71d406a1d`
* pool - `46b4c2d5fcac623d9668b19d0ce68f9da5a18029f3dffa8afded436ab16e8883`
Loading
Loading