-
Notifications
You must be signed in to change notification settings - Fork 3
feat: adjustable fee configs #1160
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
79fa8a8
feat: fee configs
williamrusdyputra f11636d
chore: create a function to call the fee config
williamrusdyputra 693fa04
fix: apply coderabbit suggestions
williamrusdyputra 8d5e609
fix: type
williamrusdyputra 11438aa
fix: if not found config
williamrusdyputra 8a8128c
fix: naming
williamrusdyputra 97d0caf
chore: remove default insert
williamrusdyputra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| -- Fee configuration table for ERC20 bridge operations | ||
| -- Stores configurable fees and treasury address for deposit and withdraw operations | ||
|
|
||
| CREATE TABLE IF NOT EXISTS fee_configs ( | ||
| operation_type TEXT NOT NULL, | ||
| fee_percentage NUMERIC(4, 4) NOT NULL, | ||
| treasury_address TEXT NOT NULL, | ||
| created_at INT8 NOT NULL, | ||
| updated_at INT8 NOT NULL, | ||
|
|
||
| PRIMARY KEY (operation_type), | ||
|
|
||
| -- Constraints | ||
| CHECK (operation_type IN ('deposit', 'withdraw')), | ||
| CHECK (fee_percentage >= 0 AND fee_percentage <= 1), -- 0% to 100% | ||
| CHECK (treasury_address LIKE '0x%' AND LENGTH(treasury_address) = 42) | ||
|
williamrusdyputra marked this conversation as resolved.
|
||
| ); | ||
|
|
||
| -- Action to get fee configuration by operation type | ||
| CREATE OR REPLACE ACTION get_fee_config_by_type($operation_type TEXT) | ||
| PUBLIC VIEW RETURNS ( | ||
| fee_percentage NUMERIC(4, 4), | ||
| treasury_address TEXT | ||
| ) { | ||
| FOR $config IN SELECT fee_percentage, treasury_address FROM fee_configs WHERE operation_type = $operation_type { | ||
| RETURN $config.fee_percentage, $config.treasury_address; | ||
| } | ||
| }; | ||
|
williamrusdyputra marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| CREATE OR REPLACE ACTION get_erc20_bridge_info() | ||
| PUBLIC VIEW RETURNS ( | ||
| chain TEXT, | ||
| escrow TEXT, | ||
| epoch_period TEXT, | ||
| erc20 TEXT, | ||
| decimals INT, | ||
| balance NUMERIC(78, 0), | ||
| synced BOOLEAN, | ||
| synced_at INT8, | ||
| enabled BOOLEAN | ||
| ) { | ||
| FOR $row IN sepolia_bridge.info() { | ||
| RETURN $row.chain, $row.escrow, $row.epoch_period, $row.erc20, $row.decimals, $row.balance, $row.synced, $row.synced_at, $row.enabled; | ||
| } | ||
| }; | ||
|
|
||
| -- TESTNET | ||
| CREATE OR REPLACE ACTION sepolia_wallet_balance($wallet_address TEXT) PUBLIC VIEW RETURNS (balance NUMERIC(78, 0)) { | ||
| $balance := sepolia_bridge.balance($wallet_address); | ||
| RETURN $balance; | ||
| }; | ||
|
|
||
| CREATE OR REPLACE ACTION sepolia_admin_bridge_tokens($amount TEXT) PUBLIC { | ||
|
williamrusdyputra marked this conversation as resolved.
|
||
| $num_amount := $amount::NUMERIC(78, 0); | ||
|
|
||
| -- Get fee configuration for withdraw | ||
| $found := 0; | ||
| FOR $config IN SELECT fee_percentage, treasury_address FROM fee_configs WHERE operation_type = 'withdraw' ORDER BY created_at DESC LIMIT 1 { | ||
| $fee := $num_amount * $config.fee_percentage; | ||
|
|
||
| IF $fee > 0::NUMERIC(78, 0) { | ||
| sepolia_bridge.lock($fee); | ||
| sepolia_bridge.unlock($config.treasury_address, $fee); | ||
| } | ||
|
|
||
| -- Bridge the rest to users | ||
| sepolia_bridge.bridge($num_amount - $fee); | ||
| $found := 1; | ||
| } | ||
|
|
||
| IF $found = 0 { ERROR('No fee_configs rows for operation_type=withdraw'); } | ||
| }; | ||
|
|
||
| -- MAINNET | ||
| CREATE OR REPLACE ACTION mainnet_wallet_balance($wallet_address TEXT) PUBLIC VIEW RETURNS (balance NUMERIC(78, 0)) { | ||
| $balance := mainnet_bridge.balance($wallet_address); | ||
| RETURN $balance; | ||
| }; | ||
|
|
||
| CREATE OR REPLACE ACTION mainnet_admin_bridge_tokens($amount TEXT) PUBLIC { | ||
| $num_amount := $amount::NUMERIC(78, 0); | ||
|
|
||
| -- Get fee configuration for withdraw | ||
| $found := 0; | ||
| FOR $config IN SELECT fee_percentage, treasury_address FROM fee_configs WHERE operation_type = 'withdraw' ORDER BY created_at DESC LIMIT 1 { | ||
| $fee := $num_amount * $config.fee_percentage; | ||
|
|
||
| IF $fee > 0::NUMERIC(78, 0) { | ||
| mainnet_bridge.lock($fee); | ||
| mainnet_bridge.unlock($config.treasury_address, $fee); | ||
| } | ||
|
|
||
| -- Bridge the rest to users | ||
| mainnet_bridge.bridge($num_amount - $fee); | ||
| $found := 1; | ||
| } | ||
|
|
||
| IF $found = 0 { ERROR('No fee_configs rows for operation_type=withdraw'); } | ||
| }; | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.