diff --git a/.eslintrc.js b/.eslintrc.js index af2ea9c..e905aad 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,6 +11,7 @@ module.exports = { 'plugin:import/typescript', ], rules: { + 'import/no-named-as-default': 'off', '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/explicit-module-boundary-types': 'off', 'sort-imports-es6-autofix/sort-imports-es6': 'error', diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index de6ca83..36bc7e8 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -14,19 +14,13 @@ jobs: strategy: fail-fast: false matrix: - tests: [xcm-transfer] + tests: [xcm-transfer, staking] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: submodules: recursive - name: setup node - uses: actions/setup-node@v4 - with: - node-version: 18.x - - name: Setup yarn - run: npm install -g yarn - - name: setup node env uses: actions/setup-node@v4 with: node-version: 18.x diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0605754..4eba49a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,25 +10,12 @@ env: DB_PATH: ./db.sqlite jobs: - # lint: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v3 - # with: - # submodules: recursive - # - name: Use Node.js - # uses: actions/setup-node@v3 - # with: - # node-version: 18.x - # cache: 'yarn' - # - run: yarn --immutable - # - run: yarn lint tests: timeout-minutes: 30 strategy: fail-fast: false matrix: - tests: [xcm-transfer] + tests: [xcm-transfer, staking] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -36,15 +23,10 @@ jobs: submodules: recursive - name: setup node uses: actions/setup-node@v4 - with: - node-version: 18.x - - name: Setup yarn - run: npm install -g yarn - - name: setup node env - uses: actions/setup-node@v3 with: node-version: 18.x cache: 'yarn' - run: yarn --immutable + - run: yarn lint - run: yarn update-env - run: yarn test tests/${{ matrix.tests }} diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 2d7b673..a15411a 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -19,12 +19,6 @@ jobs: with: submodules: recursive - name: setup node - uses: actions/setup-node@v4 - with: - node-version: 18.x - - name: Setup yarn - run: npm install -g yarn - - name: setup node env uses: actions/setup-node@v4 with: node-version: 18.x diff --git a/tests/staking/tier-threshold.test.ts b/tests/staking/tier-threshold.test.ts new file mode 100644 index 0000000..3dabd06 --- /dev/null +++ b/tests/staking/tier-threshold.test.ts @@ -0,0 +1,180 @@ +import { expect } from 'vitest' +import { given } from '../../helpers' + +given('astar')('Number of slots adjusted based on price', async ({ networks: { astar } }) => { + const advanceNextEra = async () => { + const state = await astar.api.query.dappStaking.activeProtocolState() + await astar.dev.newBlock({ count: 1, unsafeBlockHeight: state.nextEraStart.toNumber() }) + } + + // set price to $0.10 + await astar.dev.setStorage({ + priceAggregator: { + valuesCircularBuffer: { + head: 1, + buffer: [ + 100_000_000_000_000_000n, // $0.10 + ], + }, + }, + }) + + await advanceNextEra() + + expect((await astar.api.query.dappStaking.tierConfig()).toHuman()).toMatchInlineSnapshot(` + { + "numberOfSlots": "150", + "rewardPortion": [ + "25.00%", + "47.00%", + "25.00%", + "3.00%", + ], + "slotsPerTier": [ + "7", + "30", + "45", + "67", + ], + "tierThresholds": [ + { + "DynamicTvlAmount": { + "amount": "200,000,000,000,000,000,100,000,000", + "minimumAmount": "200,000,000,000,000,000,000,000,000", + }, + }, + { + "DynamicTvlAmount": { + "amount": "50,000,000,000,000,000,025,000,000", + "minimumAmount": "50,000,000,000,000,000,000,000,000", + }, + }, + { + "DynamicTvlAmount": { + "amount": "15,000,000,000,000,000,000,000,000", + "minimumAmount": "15,000,000,000,000,000,000,000,000", + }, + }, + { + "FixedTvlAmount": { + "amount": "1,500,000,000,000,000,000,000,000", + }, + }, + ], + } + `) + + // set price to $0.50 + await astar.dev.setStorage({ + priceAggregator: { + valuesCircularBuffer: { + head: 1, + buffer: [ + 500_000_000_000_000_000n, // $0.50 + ], + }, + }, + }) + + await advanceNextEra() + + expect((await astar.api.query.dappStaking.tierConfig()).toHuman()).toMatchInlineSnapshot(` + { + "numberOfSlots": "550", + "rewardPortion": [ + "25.00%", + "47.00%", + "25.00%", + "3.00%", + ], + "slotsPerTier": [ + "27", + "110", + "165", + "247", + ], + "tierThresholds": [ + { + "DynamicTvlAmount": { + "amount": "200,000,000,000,000,000,000,000,000", + "minimumAmount": "200,000,000,000,000,000,000,000,000", + }, + }, + { + "DynamicTvlAmount": { + "amount": "50,000,000,000,000,000,000,000,000", + "minimumAmount": "50,000,000,000,000,000,000,000,000", + }, + }, + { + "DynamicTvlAmount": { + "amount": "15,000,000,000,000,000,000,000,000", + "minimumAmount": "15,000,000,000,000,000,000,000,000", + }, + }, + { + "FixedTvlAmount": { + "amount": "1,500,000,000,000,000,000,000,000", + }, + }, + ], + } + `) + + // set price to $0.05 + await astar.dev.setStorage({ + priceAggregator: { + valuesCircularBuffer: { + head: 1, + buffer: [ + 50_000_000_000_000_000n, // $0.05 + ], + }, + }, + }) + + await advanceNextEra() + + expect((await astar.api.query.dappStaking.tierConfig()).toHuman()).toMatchInlineSnapshot(` + { + "numberOfSlots": "100", + "rewardPortion": [ + "25.00%", + "47.00%", + "25.00%", + "3.00%", + ], + "slotsPerTier": [ + "5", + "20", + "30", + "45", + ], + "tierThresholds": [ + { + "DynamicTvlAmount": { + "amount": "300,000,000,000,000,000,000,000,000", + "minimumAmount": "200,000,000,000,000,000,000,000,000", + }, + }, + { + "DynamicTvlAmount": { + "amount": "75,000,000,000,000,000,000,000,000", + "minimumAmount": "50,000,000,000,000,000,000,000,000", + }, + }, + { + "DynamicTvlAmount": { + "amount": "20,000,000,000,000,000,000,000,000", + "minimumAmount": "15,000,000,000,000,000,000,000,000", + }, + }, + { + "FixedTvlAmount": { + "amount": "1,500,000,000,000,000,000,000,000", + }, + }, + ], + } + `) +})