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 : ExitFee Settings moved to contract! #42

Closed
wants to merge 16 commits into from
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.20.0
20.17.0
74 changes: 69 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,78 @@ All configuration is done via environment variables. See all variables at [.env.

## Building & Running

1. Make sure dependencies are installed - run `yarn` in the base directory
2. Build `yarn build`
3. Run `yarn start`
### Development & Production

## Postgresql
Make sure dependencies are installed - run script below in the base directory
```shell
pnpm install
```

Starts the project in development mode using ts-node to execute the script at ./src/exec/run.ts.
```shell
pnpm start
```


Starts the project in production mode by running the pre-built script at ./build/src/exec/run.js.
```shell
pnpm start:prod
```

### Build & Clean

Compiling smart contracts using Hardhat.
Compiling TypeScript files based on tsconfig.json.

```shell
pnpm build
```


Cleans the project by removing the dist/ folder and TypeScript build info files.
```shell
pnpm clean
```

### Linting

Runs both linting checks and applies automatic formatting fixes.
```shell
pnpm lint
```

Automatically formats TypeScript files in src, exec, and test directories based on Prettier configuration (.prettierrc.json).
```shell
pnpm lint:fix
```

Performs TSLint checks and displays output in a stylish format.
```shell
pnpm lint:check
```

### Database

Starts a PostgreSQL database in a Docker container with:
- Database Name: **lightbridge**
- Password: **abcdef**
- Exposed on port **5432**.

```shell
pnpm db:start
```

Connect to Postgres on CLI:
`psql --username postgres -d postgres --password`
```shell
psql --username postgres -d postgres --password
```

### Testing

Runs all unit and integration tests using Hardhat, with stack traces enabled for easier debugging.
```shell
pnpm test
```

## Deployments

Expand Down
40 changes: 35 additions & 5 deletions contracts/LightBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ contract LightBridge is PausableUpgradeable, MulticallUpgradeable {
/// @dev The total number of disbursements processed.
mapping(uint256 => uint256) public totalDisbursements;

// @dev depositId to failed status and disbursement info
/// @dev depositId to failed status and disbursement info
mapping(uint256 => FailedNativeDisbursement) public failedNativeDisbursements;

/// @dev exit fee (in percentage 1% = 1) to deduct fee while disbursement of asset.
uint256 public exitFee;

/********************
* Events *
********************/
Expand Down Expand Up @@ -152,6 +155,11 @@ contract LightBridge is PausableUpgradeable, MulticallUpgradeable {
uint32 indexed toChainId,
bool supported
);

event ExitFeeSet(
uint256 oldFee,
uint256 exitFee
);

/**********************
* Function Modifiers *
Expand Down Expand Up @@ -180,12 +188,19 @@ contract LightBridge is PausableUpgradeable, MulticallUpgradeable {
/********************
* Public Functions *
********************/

/// @dev Initialize this contract
function initialize() external onlyNotInitialized() initializer() {
/**
* @dev Initialize this contract
*
* @param _exitFee exit fee (in percentage 1 - 100) can be use to deduct the fee while withdrawal.
*/
function initialize(uint256 _exitFee) external onlyNotInitialized() initializer() {
require(_exitFee > 0, "Exit fee cannot less than or equal to zero"); // should be more than 0
wsdt marked this conversation as resolved.
Show resolved Hide resolved
sk-enya marked this conversation as resolved.
Show resolved Hide resolved
require(_exitFee <= 100, "Exit fee too high"); // Max 100%

disburser = msg.sender;
owner = msg.sender;

exitFee = _exitFee;

__Context_init_unchained();
__Pausable_init_unchained();
__Multicall_init_unchained();
Expand Down Expand Up @@ -497,4 +512,19 @@ contract LightBridge is PausableUpgradeable, MulticallUpgradeable {

emit MaxTransferAmountPerDaySet(_token, _toChainId, pastMaxTransferAmountPerDay, _maxTransferAmountPerDay);
}

/**
* @dev Sets exit fee (in percentage 1 - 100) to be used to calculate the fee to deduct while exit or withdrawal of asset
*
* @param _exitFee The exit in fee in percentage
*/
function setExitFee(uint256 _exitFee) external onlyOwner() {
require(_exitFee > 0, "Exit fee cannot less than or equal to zero"); // should be more than 0
wsdt marked this conversation as resolved.
Show resolved Hide resolved
require(_exitFee <= 100, "Exit fee too high"); // Max 100%

emit ExitFeeSet(exitFee, _exitFee);

exitFee = _exitFee;
}

}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"scripts": {
"start": "ts-node ./src/exec/run.ts",
"start:prod": "node ./build/src/exec/run.js",
"build": "yarn build:contracts && yarn build:typescript",
"build": "pnpm build:contracts && pnpm build:typescript",
"build:contracts": "hardhat compile",
"build:typescript": "tsc -p ./tsconfig.json",
"clean": "rimraf dist/ ./tsconfig.tsbuildinfo",
"lint": "yarn lint:fix && yarn lint:check",
"lint": "pnpm lint:fix && pnpm lint:check",
"lint:fix": "prettier --config .prettierrc.json --write \"{src,exec,test}/**/*.ts\"",
"lint:check": "tslint --format stylish --project .",
"db:start": "docker run -e POSTGRES_DB=lightbridge -e POSTGRES_PASSWORD=abcdef -p 5432:5432 postgres",
Expand Down Expand Up @@ -66,7 +66,7 @@
},
"husky": {
"hooks": {
"pre-commit": "yarn build && yarn lint && yarn depcheck"
"pre-commit": "pnpm build && pnpm lint && pnpm depcheck"
}
}
}
Loading
Loading