Skip to content

Commit 7fe3e6c

Browse files
authored
Merge pull request #22 from oasisprotocol/rube/issue-11-simplify-price-calculation
fix: update price calc and add contracts to ci-test
2 parents 41d7134 + 7d74076 commit 7fe3e6c

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

.github/workflows/ci-test.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
# NOTE: This name appears in GitHub's Checks API and in workflow's status badge.
22
name: ci-test
33

4-
# Trigger the workflow when:
54
on:
6-
# A push occurs to one of the matched branches.
75
push:
86
branches:
97
- main
108
- master
119
- stable/*
12-
# Or when a pull request event occurs for a pull request against one of the
13-
# matched branches.
1410
pull_request:
1511
branches:
1612
- main
@@ -26,6 +22,38 @@ env:
2622
CMAKE_POLICY_VERSION_MINIMUM: 3.5
2723

2824
jobs:
25+
test-contracts:
26+
name: test-contracts
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
- name: Setup Bun
33+
uses: oven-sh/setup-bun@v2
34+
35+
- name: Cache Bun dependencies
36+
uses: actions/cache@v4
37+
with:
38+
path: |
39+
~/.bun/install/cache
40+
contracts/node_modules
41+
key: ${{ runner.os }}-bun-${{ hashFiles('contracts/bun.lock') }}
42+
restore-keys: |
43+
${{ runner.os }}-bun-
44+
45+
- name: Install dependencies
46+
working-directory: ./contracts
47+
run: bun install --frozen-lockfile
48+
49+
- name: Compile contracts
50+
working-directory: ./contracts
51+
run: bun hardhat compile
52+
53+
- name: Run tests
54+
working-directory: ./contracts
55+
run: bun hardhat test
56+
2957
test-paymaster-relayer:
3058
name: test-paymaster-relayer
3159
runs-on: ubuntu-latest
@@ -38,10 +66,11 @@ jobs:
3866
with:
3967
python-version: '3.12'
4068
enable-cache: true
69+
cache-dependency-glob: "paymaster-relayer/uv.lock"
4170

4271
- name: Install dependencies
4372
working-directory: ./paymaster-relayer
44-
run: uv sync --dev
73+
run: uv sync --dev --frozen
4574

4675
- name: Run tests
4776
working-directory: ./paymaster-relayer

contracts/bun.lock

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/contracts/sapphire/CrossChainPaymaster.sol

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -410,20 +410,16 @@ contract CrossChainPaymaster is
410410
uint8 tDec = tokenUsd.decimals();
411411
uint8 rDec = roseFeed.decimals();
412412

413-
// Normalize ROSE price to 18 decimals
414-
uint256 normalizedRosePrice;
415-
if (rDec < NORMALIZED_DECIMALS) {
416-
normalizedRosePrice = uint256(rPrice) * (10 ** (NORMALIZED_DECIMALS - rDec));
417-
} else if (rDec > NORMALIZED_DECIMALS) {
418-
normalizedRosePrice = uint256(rPrice) / (10 ** (rDec - NORMALIZED_DECIMALS));
419-
} else {
420-
normalizedRosePrice = uint256(rPrice);
421-
}
422-
423-
// roseAmount = tokenAmount * (tokenUsd / roseUsd) adjusted to 18 decimals
424-
uint256 num = Math.mulDiv(tokenAmount, uint256(tPrice), 10 ** tokenDec);
425-
num = Math.mulDiv(num, 10 ** NORMALIZED_DECIMALS, 10 ** tDec);
426-
roseAmount = Math.mulDiv(num, 1e18, normalizedRosePrice);
413+
// Convert token amount to USD value (normalized to 18 decimals)
414+
// Note: Assumes tDec <= 18
415+
uint256 usdValue = Math.mulDiv(
416+
tokenAmount,
417+
uint256(tPrice) * (10 ** (NORMALIZED_DECIMALS - tDec)),
418+
10 ** tokenDec
419+
);
420+
421+
// Convert USD value to ROSE amount (result in 18 decimals)
422+
roseAmount = Math.mulDiv(usdValue, 10 ** rDec, uint256(rPrice));
427423
}
428424

429425
/// @notice Accepts ROSE funding

0 commit comments

Comments
 (0)