Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into loans/multi-cashflows
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed May 24, 2024
2 parents 77dada6 + 5fc0465 commit 3321024
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/actions/sccache-gcloud/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ runs:

- name: Auth gcloud
id: gauth
uses: google-github-actions/auth@35b0e87d162680511bf346c299f71c9c5c379033 # @v1.1.1
uses: google-github-actions/auth@55bd3a7c6e2ae7cf1877fd1ccb9d54c0503c457c # @v2.1.2
with:
workload_identity_provider: ${{ inputs.GWIP }}
service_account: ${{ inputs.GSA }}

- name: Run sccache-cache
uses: mozilla-actions/sccache-action@8417cffc2ec64127ad83077aceaa8631f7cdc83e #v0.0.3
uses: mozilla-actions/sccache-action@2e7f9ec7921547d4b46598398ca573513895d0bd #v0.0.4

- name: set GCS bucket sccache variables
shell: bash
Expand Down
21 changes: 14 additions & 7 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ on:
# Keep in mind the Docker tagging on the "metadata" step if you add new triggers
workflow_dispatch: # In case a repo contributor needs a specific docker tag built.
push:
tags: ['v*.*.*']
branches: [main]
release:
# Release logic:
# https://docs.github.com/en/webhooks/webhook-events-and-payloads?actionType=unpublished#release
types: [ created ] # GITHUB_REF == tag pushed with the release
#
types: [ released ] # GITHUB_REF == tag pushed with the release
pull_request:
paths:
- ".github/workflows/build-docker.yml"
Expand Down Expand Up @@ -35,13 +37,13 @@ jobs:
uses: docker/setup-buildx-action@0d103c3126aa41d772a8362f6aa67afac040f80c #v3.1.0

- name: DockerHub Registry Login
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 #v3.1.0
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

- name: Github Registry login
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 #v3.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand All @@ -55,7 +57,12 @@ jobs:
with:
images: |
ghcr.io/centrifuge/centrifuge-chain
${{ github.event_name != 'pull_request' && 'centrifugeio/centrifuge-chain' || ''}}
${{ (github.event_name == 'release' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))) && 'centrifugeio/centrifuge-chain' || ''}}
# TAGS:
# v.X.Y.Z when pushing a git tag (or a release)
# latest when triggered by a release
# PRXYZ when triggered from a PR (testing)
# {BRANCH_NAME} when triggered from branch push
tags: |
type=semver,pattern={{raw}},prefix=${{ matrix.target == 'test' && 'test-' || '' }}
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
Expand All @@ -77,7 +84,7 @@ jobs:
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Build and push centrifugeio/centrifuge-chain
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 #v5.1.0
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 #v5.3.0
with:
context: .
file: ./docker/centrifuge-chain/Dockerfile
Expand Down Expand Up @@ -105,12 +112,12 @@ jobs:
enable-url-completion: true

- name: Update GitHub release
if: github.event_name == 'release' && matrix.target == 'release'
if: github.event_name == 'release' && github.event.action == 'released' && matrix.target == 'release'
uses: softprops/action-gh-release@v1
with:
append_body: true
body: |
**Docker tags:**
**Docker tags (${{ env.NOW }}):**
${{ steps.meta.outputs.tags }}
- if: failure()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
steps:
# PREP
- name: Check out code
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab #3.5.2
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b #4.1.4

- name: Prep build on Ubuntu
uses: ./.github/actions/prep-ubuntu
Expand Down
19 changes: 10 additions & 9 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,21 @@ jobs:
RUST_BACKTRACE: 1
run: |
cargo tarpaulin --timeout 300 -e runtime-integration-tests --features fast-runtime \
--exclude-files runtime/*/src/migrations.rs --exclude-files runtime/common/src/migrations \
--exclude-files pallets/rewards/src/migrations/new_instance.rs --exclude-files pallets/block-rewards/src/migrations.rs \
--workspace --exclude-files **/mock.rs **/weights.rs **/weights/* --out xml
--exclude-files runtime/*/src/migrations.rs \
--exclude-files runtime/common/src/migrations \
--exclude-files pallets/rewards/src/migrations/new_instance.rs \
--exclude-files pallets/block-rewards/src/migrations.rs \
--exclude-files **/mock.rs \
--exclude-files **/weights.rs \
--exclude-files **/weights/* \
--exclude-files node/ \
--exclude-files runtime \
--workspace --out xml
# UPLOAD REPORTS (requires cargo 1.70.0)
- name: Upload to codecov.io
if: ${{ always() }}
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
# token: ${{ secrets.CODECOV_TOKEN }}
# files: ./coverage1.xml,./coverage2.xml # optional
# flags: unittests # optional
# name: codecov-umbrella # optional
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
done
- name: upload Docs files
uses: actions/upload-pages-artifact@0252fc4ba7626f0298f0cf00902a25c6afc77fa8 # v3.0
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0
with:
path: ./target/doc

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sanity-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
lint-fmt, lint-clippy, cargo-build, docs-build, lint-taplo]
steps:
- name: Check out code
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab #3.5.2
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b #4.1.4

- name: Prep build
uses: ./.github/actions/prep-ubuntu
Expand All @@ -41,7 +41,7 @@ jobs:
runtime: [altair, centrifuge]
steps:
- name: Check out code
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab #3.5.2
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b #4.1.4

- name: Prep build
uses: ./.github/actions/prep-ubuntu
Expand Down
7 changes: 7 additions & 0 deletions codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
github_checks:
annotations: false
coverage:
status:
project:
default:
informational: true
9 changes: 9 additions & 0 deletions libs/types/src/oracles.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cfg_primitives::{LoanId, PoolId};
use frame_support::pallet_prelude::RuntimeDebug;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
Expand Down Expand Up @@ -26,10 +27,18 @@ pub type Isin = [u8; 12];
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum OracleKey {
/// Identify a Isin price
#[codec(index = 0)]
Isin(Isin),

/// Identify a conversion from the first currency to the second one
#[codec(index = 1)]
ConversionRatio(CurrencyId, CurrencyId),

/// Identifies a single pool-loan-id combination.
/// This key is a fallback solution if no other keys are applicable for the
/// given oracle.
#[codec(index = 2)]
PoolLoanId(PoolId, LoanId),
}

impl From<(CurrencyId, CurrencyId)> for OracleKey {
Expand Down
6 changes: 3 additions & 3 deletions pallets/loans/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ pub mod pallet {
Err(Error::<T>::UnrelatedChangeId)?
};

let (_, _count) = Self::transfer_debt_action(
let (repaid_amount, _count) = Self::transfer_debt_action(
&who,
pool_id,
from_loan_id,
Expand Down Expand Up @@ -946,7 +946,7 @@ pub mod pallet {
repaid_amount: RepaidInput<T>,
borrow_amount: PrincipalInput<T>,
permissionless: bool,
) -> Result<(T::Balance, u32), DispatchError> {
) -> Result<(RepaidInput<T>, u32), DispatchError> {
ensure!(
from_loan_id != to_loan_id,
Error::<T>::TransferDebtToSameLoan
Expand All @@ -963,7 +963,7 @@ pub mod pallet {
let count =
Self::borrow_action(who, pool_id, to_loan_id, &borrow_amount, permissionless)?;

Ok((repaid_amount.repaid_amount()?.total()?, count))
Ok((repaid_amount, count))
}

/// Set the maturity date of the loan to this instant.
Expand Down
2 changes: 1 addition & 1 deletion pallets/loans/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::{
ActivePricing, Pricing,
},
},
pallet::{ActiveLoans, CreatedLoan, Error, LastLoanId, PortfolioValuation},
pallet::{ActiveLoans, CreatedLoan, Error, Event, LastLoanId, PortfolioValuation},
types::{
cashflow::{
tests::{last_secs_from_ymd, secs_from_ymdhms},
Expand Down
21 changes: 16 additions & 5 deletions pallets/loans/src/tests/repay_loan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,29 @@ fn with_success_half_amount() {
let loan_id = util::create_loan(util::base_internal_loan());
util::borrow_loan(loan_id, PrincipalInput::Internal(COLLATERAL_VALUE / 2));

let amount = RepaidInput {
principal: PrincipalInput::Internal(COLLATERAL_VALUE / 2),
interest: 1234, /* Will not be used */
unscheduled: 0,
};

config_mocks(COLLATERAL_VALUE / 2);
assert_ok!(Loans::repay(
RuntimeOrigin::signed(BORROWER),
POOL_A,
loan_id,
RepaidInput {
principal: PrincipalInput::Internal(COLLATERAL_VALUE / 2),
interest: 0,
unscheduled: 0,
},
amount.clone()
));
assert_eq!(0, util::current_loan_debt(loan_id));

System::assert_last_event(RuntimeEvent::Loans(Event::Repaid {
pool_id: POOL_A,
loan_id: loan_id,
amount: RepaidInput {
interest: 0,
..amount
},
}));
});
}

Expand Down
17 changes: 14 additions & 3 deletions pallets/loans/src/tests/transfer_debt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ fn with_success_internals() {

let repay_amount = RepaidInput {
principal: PrincipalInput::Internal(COLLATERAL_VALUE),
interest: 0,
interest: 1234, /* Will not be used */
unscheduled: 0,
};
let borrow_amount = PrincipalInput::Internal(COLLATERAL_VALUE);
Expand All @@ -372,8 +372,8 @@ fn with_success_internals() {
POOL_A,
loan_1,
loan_2,
repay_amount,
borrow_amount,
repay_amount.clone(),
borrow_amount.clone(),
));

assert_ok!(Loans::apply_transfer_debt(
Expand All @@ -384,6 +384,17 @@ fn with_success_internals() {

assert_eq!(0, util::current_loan_debt(loan_1));
assert_eq!(COLLATERAL_VALUE, util::current_loan_debt(loan_2));

System::assert_last_event(RuntimeEvent::Loans(Event::DebtTransferred {
pool_id: POOL_A,
from_loan_id: loan_1,
to_loan_id: loan_2,
repaid_amount: RepaidInput {
interest: 0,
..repay_amount
},
borrow_amount,
}));
});
}

Expand Down

0 comments on commit 3321024

Please sign in to comment.