-
Notifications
You must be signed in to change notification settings - Fork 3
feat: apply fee when withdrawing TRUF tokens #1158
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -1,164 +1,48 @@ | ||
| /** | ||
| Bridge Mechanism: | ||
| 1. Call [chain]_admin_lock_tokens(), to lock x amount of tokens from user. | ||
| 2. Call [chain]_admin_issue_tokens(), to issue the locked tokens to layer-1 (escrow on ethereum). | ||
| 3. Frontend will call `list_wallet_rewards --namespace [chain]_bridge` to get inclusion proofs. | ||
| 4. Frontend will call claimReward function on escrow contract using the inclusion proofs given. | ||
| 5. Receiver wallet will get the tokens after claim is done. | ||
| */ | ||
| 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)) { | ||
| $lower_caller TEXT := LOWER(@caller); | ||
|
|
||
| -- Permission Check: Ensure caller has the 'system:erc20_bridge_writer' role. | ||
| $has_permission BOOL := false; | ||
| for $row in are_members_of('system', 'erc20_bridge_writer', ARRAY[$lower_caller]) { | ||
| if $row.wallet = $lower_caller AND $row.is_member { | ||
| $has_permission := true; | ||
| break; | ||
| } | ||
| } | ||
| if NOT $has_permission { | ||
| ERROR('Caller does not have the required system:erc20_bridge_writer role to read balance.'); | ||
| } | ||
|
|
||
| $balance := sepolia_bridge.balance($wallet_address); | ||
| return $balance; | ||
| }; | ||
|
|
||
| CREATE OR REPLACE ACTION sepolia_admin_lock_tokens($wallet_address TEXT, $amount TEXT) PUBLIC { | ||
| $lower_caller TEXT := LOWER(@caller); | ||
|
|
||
| -- Permission Check: Ensure caller has the 'system:erc20_bridge_writer' role. | ||
| $has_permission BOOL := false; | ||
| for $row in are_members_of('system', 'erc20_bridge_writer', ARRAY[$lower_caller]) { | ||
| if $row.wallet = $lower_caller AND $row.is_member { | ||
| $has_permission := true; | ||
| break; | ||
| } | ||
| } | ||
| if NOT $has_permission { | ||
| ERROR('Caller does not have the required system:erc20_bridge_writer role to lock tokens.'); | ||
| } | ||
|
|
||
| sepolia_bridge.lock_admin($wallet_address, $amount::NUMERIC(78, 0)); | ||
| }; | ||
|
|
||
| CREATE OR REPLACE ACTION sepolia_admin_unlock_tokens($to_address TEXT, $amount TEXT) PUBLIC { | ||
| $lower_caller TEXT := LOWER(@caller); | ||
|
|
||
| -- Permission Check: Ensure caller has the 'system:erc20_bridge_writer' role. | ||
| $has_permission BOOL := false; | ||
| for $row in are_members_of('system', 'erc20_bridge_writer', ARRAY[$lower_caller]) { | ||
| if $row.wallet = $lower_caller AND $row.is_member { | ||
| $has_permission := true; | ||
| break; | ||
| } | ||
| } | ||
| if NOT $has_permission { | ||
| ERROR('Caller does not have the required system:erc20_bridge_writer role to unlock tokens.'); | ||
| } | ||
|
|
||
| sepolia_bridge.unlock($to_address, $amount::NUMERIC(78, 0)); | ||
| }; | ||
|
|
||
| CREATE OR REPLACE ACTION sepolia_admin_issue_tokens($to_address TEXT, $amount TEXT) PUBLIC { | ||
| $lower_caller TEXT := LOWER(@caller); | ||
|
|
||
| -- Permission Check: Ensure caller has the 'system:erc20_bridge_writer' role. | ||
| $has_permission BOOL := false; | ||
| for $row in are_members_of('system', 'erc20_bridge_writer', ARRAY[$lower_caller]) { | ||
| if $row.wallet = $lower_caller AND $row.is_member { | ||
| $has_permission := true; | ||
| break; | ||
| } | ||
| } | ||
| if NOT $has_permission { | ||
| ERROR('Caller does not have the required system:erc20_bridge_writer role to issue tokens.'); | ||
| } | ||
|
|
||
| sepolia_bridge.issue($to_address, $amount::NUMERIC(78, 0)); | ||
| RETURN $balance; | ||
| }; | ||
|
|
||
| CREATE OR REPLACE ACTION sepolia_admin_bridge_tokens($amount TEXT) PUBLIC { | ||
| sepolia_bridge.bridge($amount::NUMERIC(78, 0)); | ||
| -- Calculate 1% fee and lock it in our treasury | ||
| $numAmount := $amount::NUMERIC(78, 0); | ||
| $fee := $numAmount * 0.01; | ||
| sepolia_bridge.lock($fee); | ||
|
|
||
| -- Bridge the rest to users | ||
| sepolia_bridge.bridge($numAmount - $fee); | ||
| }; | ||
|
|
||
| -- MAINNET | ||
| CREATE OR REPLACE ACTION mainnet_wallet_balance($wallet_address TEXT) PUBLIC VIEW RETURNS (balance NUMERIC(78, 0)) { | ||
| $lower_caller TEXT := LOWER(@caller); | ||
|
|
||
| -- Permission Check: Ensure caller has the 'system:erc20_bridge_writer' role. | ||
| $has_permission BOOL := false; | ||
| for $row in are_members_of('system', 'erc20_bridge_writer', ARRAY[$lower_caller]) { | ||
| if $row.wallet = $lower_caller AND $row.is_member { | ||
| $has_permission := true; | ||
| break; | ||
| } | ||
| } | ||
| if NOT $has_permission { | ||
| ERROR('Caller does not have the required system:erc20_bridge_writer role to read balance.'); | ||
| } | ||
|
|
||
| $balance := mainnet_bridge.balance($wallet_address); | ||
| return $balance; | ||
| }; | ||
|
|
||
| CREATE OR REPLACE ACTION mainnet_admin_lock_tokens($wallet_address TEXT, $amount TEXT) PUBLIC { | ||
| $lower_caller TEXT := LOWER(@caller); | ||
|
|
||
| -- Permission Check: Ensure caller has the 'system:erc20_bridge_writer' role. | ||
| $has_permission BOOL := false; | ||
| for $row in are_members_of('system', 'erc20_bridge_writer', ARRAY[$lower_caller]) { | ||
| if $row.wallet = $lower_caller AND $row.is_member { | ||
| $has_permission := true; | ||
| break; | ||
| } | ||
| } | ||
| if NOT $has_permission { | ||
| ERROR('Caller does not have the required system:erc20_bridge_writer role to lock tokens.'); | ||
| } | ||
|
|
||
| mainnet_bridge.lock_admin($wallet_address, $amount::NUMERIC(78, 0)); | ||
| }; | ||
|
|
||
| CREATE OR REPLACE ACTION mainnet_admin_unlock_tokens($to_address TEXT, $amount TEXT) PUBLIC { | ||
| $lower_caller TEXT := LOWER(@caller); | ||
|
|
||
| -- Permission Check: Ensure caller has the 'system:erc20_bridge_writer' role. | ||
| $has_permission BOOL := false; | ||
| for $row in are_members_of('system', 'erc20_bridge_writer', ARRAY[$lower_caller]) { | ||
| if $row.wallet = $lower_caller AND $row.is_member { | ||
| $has_permission := true; | ||
| break; | ||
| } | ||
| } | ||
| if NOT $has_permission { | ||
| ERROR('Caller does not have the required system:erc20_bridge_writer role to unlock tokens.'); | ||
| } | ||
|
|
||
| mainnet_bridge.unlock($to_address, $amount::NUMERIC(78, 0)); | ||
| }; | ||
|
|
||
| CREATE OR REPLACE ACTION mainnet_admin_issue_tokens($to_address TEXT, $amount TEXT) PUBLIC { | ||
| $lower_caller TEXT := LOWER(@caller); | ||
|
|
||
| -- Permission Check: Ensure caller has the 'system:erc20_bridge_writer' role. | ||
| $has_permission BOOL := false; | ||
| for $row in are_members_of('system', 'erc20_bridge_writer', ARRAY[$lower_caller]) { | ||
| if $row.wallet = $lower_caller AND $row.is_member { | ||
| $has_permission := true; | ||
| break; | ||
| } | ||
| } | ||
| if NOT $has_permission { | ||
| ERROR('Caller does not have the required system:erc20_bridge_writer role to issue tokens.'); | ||
| } | ||
|
|
||
| mainnet_bridge.issue($to_address, $amount::NUMERIC(78, 0)); | ||
| RETURN $balance; | ||
| }; | ||
|
|
||
| CREATE OR REPLACE ACTION mainnet_admin_bridge_tokens($amount TEXT) PUBLIC { | ||
| mainnet_bridge.bridge($amount::NUMERIC(78, 0)); | ||
| -- Calculate 1% fee and lock it in our treasury | ||
| $numAmount := $amount::NUMERIC(78, 0); | ||
| $fee := $numAmount * 0.01; | ||
| mainnet_bridge.lock($fee); | ||
|
|
||
| -- Bridge the rest to users | ||
| mainnet_bridge.bridge($numAmount - $fee); | ||
| }; | ||
|
williamrusdyputra marked this conversation as resolved.
Outdated
|
||
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.