The repository contains bridge contracts and tests for them.
A bridge contract is a contract that allows the transfer of tokens between blockchains. It is a part of Allbridge Classic.
-
-
add-token- adds base/native/wrapped token to the bridgearguments:
token source(buffer) - encoded source addresstoken(trait<bridge-token>or<sip-010-trait>) - trait address on Stacks blockchaintype(uint) - one of u100/u200/u300 which represents STX/native token/wrapped tokenmin-fee(uint) - min token fee (may be adjusted later usingset-token-min-feemethod)
-
remove-token- removes base/native/wrapped token from the bridgearguments:
token source(buffer) - encoded source addresstoken(trait<bridge-token>or<sip-010-trait>) - trait address on Stacks blockchainnew-owner(principal) - the new owner of the token balance and in the case of the wrapped token - the new owner of the wrapped token
-
set-is-bridge-enabled- enables/disables bridgearguments:
is-enabled(bool) - true/false
-
set-base-fee-rate-bp- sets base fee rate in basis pointsarguments:
value(uint) - base fee rate in basis points. Should be greater than 0 and less than 10000
-
set-token-min-fee- sets a minimum fee for tokenarguments:
token address(principal) - token address on Stacks blockchainfee(uint) - new min token fee
-
set-contract-owner- sets contract owner principalarguments:
new-owner(principal) - new contract owner principal
-
set-fee-collector- sets fees collector principalarguments:
collector(principal) - new fees collector principal
-
set-validator-public-key- sets validator public keyarguments:
public-key(buffer) - validator public key
-
-
-
get-token-by-source- returns token principal bytoken-sourceandtoken-addressthrows error
u10001if the token is not foundarguments:
token source(buffer) - encoded source address
-
get-token-native- returns token configuration bytoken-addressthrows error
u10001if the token is not foundarguments:
token address(principal) - token address on Stacks blockchain
-
get-contract-owner- returns contract owner principal -
get-base-fee-rate-bp- returns base fee rate in basis points -
get-fee-collector- returns fees collector principal -
get-validator-public-key- returns validator public key -
get-is-bridge-enabled- returns true if a bridge is enabled
-
-
-
lock- the method used to lock assets on the Stacks blockchain, so afterwards it is possible to receive assets on another blockchainarguments:
lock-id(buff) - unique ID generated with extra secure logic, which is used afterwards to unlock assets on another blockchaintoken(trait<sip-010>) - token trait address on Stacks blockchainamount(uint) - amount to lock in token precisionrecipient(buff) - recipient address on another blockchaindestination(buff) - encoded destination chain identifier
After the
lockmethod is called, the following logic is executed:is-bridge-enabledflag validated. If the bridge is disabled, the method throws the erroru777- input parameters are validated (the amount is greater than 0, the token is registered in the bridge, and the destination is valid). If validation fails, the method throws an error with an error code regarding to failed assertion.
feeis calculated.feeis calculated asamount * base-fee-rate-bp / 10000. Iffeeis less thanmin-feefor the token,feeis set tomin-feelock-idis validated. Iflock-idis already used, the method throws the erroru10006. Otherwise,lock-idis added to the map of locks with details of it.feeis transferred to thefee-collectorprincipalamountwithout fee is transferred to thebridgeprincipal
-
unlock- the method used to unlock assets on the Stacks blockchain after the lock on other blockchain is confirmedarguments:
lock-id(buff) - unique ID generated with extra secure logic, which is used afterwards to unlock assets on another blockchainrecipient(buff) - recipient address on stacks blockchain will be constructed to principalamount(uint) - amount to unlock in system precisionlock-source(buff) - encoded source chain identifiertoken(trait<sip-010>) - token trait address on Stacks blockchainsignature(buff) - the signature of the lock transaction on another blockchain
After the
unlockmethod is called, the following logic is executed:is-bridge-enabledflag validated. If the bridge is disabled, the method throws the erroru777- input parameters are validated (amount is greater than 0, the token is registered in the bridge, lock-source is valid). If validation fails, the method throws an error with an error code regarding to failed assertion.
lock-sourceis validated. Iflock-sourceis not valid, the method throws the erroru20001.lock-idis validated. Iflock-idis not found in the map of unlocks, the method throws the erroru10008.signatureis validated. Ifsignatureis not valid, the method throws the erroru10012.- Information about
unlockis added to the map of unlocks with details of it, so that it is not possible to unlock the samelock-idtwice. amountis transferred to therecipientprincipal
-
-
-
<sip-010>methods:transfer- transfers tokens from the caller to the specified principalget-name- returns the human-readable name of the tokenget-symbol- returns the token symbolget-decimals- returns the number of token decimalsget-balance- returns the balance of the passed principalget-total-supply- returns the current total supplyget-token-uri- returns an optional URI that represents the metadata of this token
-
<ownable-trait>methods:get-contract-owner- returns the owner of the contractset-contract-owner- sets the owner of the contract
-
-
get-contract-owner- returns the owner of the contractset-contract-owner- sets the owner of the contract
-
transfer- transfers tokens from the caller to the specified principalget-name- returns the human-readable name of the tokenget-symbol- returns the token symbolget-decimals- returns the number of token decimalsget-balance- returns the balance of the passed principalget-total-supply- returns the current total supplyget-token-uri- returns an optional URI that represents the metadata of this token
-
Wrapped STX token implemented to be compatible with
<sip-010>trait and so all methods of<sip-010>trait are implemented for wrapped STX token. In addition, wrapped STX token implements the following methods:-
approve-contract- approves contract to transfer tokens on behalf of the callerarguments:
contract(principal) - contract principal
-
disapprove-contract- disapproves contract to transfer tokens on behalf of the callerarguments:
contract(principal) - contract principal
-
set-contract-owner- sets contract owner principalarguments:
new-owner(principal) - new contract owner principal
-
get-contract-owner- returns contract owner principal
Additionally, the
transfermethod of wrapped STX token is implemented so that only approved contracts can transfer tokens on behalf of the caller. -
-
Wrapped token is implemented to be compatible with
<sip-010>trait and so all methods of<sip-010>trait are implemented for wrapped token and also<ownable-trait>trait is implemented. In addition to that, wrapped token are implemented in a way that only the owner(bridge contract) can mint or burn tokens. Otherwise, the wrapped token will be transferable only between accounts.