Bridge Embedded Contract
The Bridge Embedded Contract is the embedded contract for the decentralized bridge deployed on the Network of Momentum.
Helper methods
CheckECDSASignature method
Checks if the ECDSA signature is correct or returns error in case it fails.
Parameters
message- the message in[]byteformatpubKeyStr- the public key instringformatsignatureStr- the signature instringformat
Returns
bool-trueif the signature passes,falseotherwise
CanPerformAction method
Checks if the parameters of the bridge are correct or returns error in case it fails.
Parameters
AccountVmContext- current context of the VM
Returns
BridgeInfoVariable- information regarding the bridgeOrchestratorInfo- information regarding the orchestrator
CheckBridgeInitialized method
Checks if the bridge is properly initialized or returns error in case it fails.
Parameters
AccountVmContext- current context of the VM
Returns
BridgeInfoVariable- information regarding the bridge
CheckOrchestratorInfoInitialized method
Checks if the orchestrator is properly initialized or returns error in case it fails.
Parameters
AccountVmContext- current context of the VM
Returns
OrchestratorInfo- information regarding the orchestrator
CheckBridgeHalted method
Checks if the bridge is halted or returns error in case it fails.
Parameters
BridgeInfoVariable- information regarding the bridgeAccountVmContext- current context of the VM
Returns
nil- the bridge is not halted
Contract implementation
The implementation of the Bridge Embedded Contract has a total of 20 methods that can be called by sending a specifically crafted account block:
WrapTokenMethod method
Method for wrapping assets. If the bridge is initialized, not halted, the destination network and the token pair exists, than a wrap token request is created.
Parameters
NetworkClass- the class of the destination networkChainId- the chain identifier of the destination networkToAddress- the address that can redeem the funds on the destination networkTokenStandard- theZTSused in thesendblockAmount- the amount used in thesendblock
Returns
AccountBlock- only if the token is owned, a burn call to the token contract is performed that burns the received tokens
UpdateWrapRequestMethod method
Method for updating the wrap request. If the signature is valid and is generated by the TSS public key, it is saved in the wrap request signature field and can be used to redeem the funds.
Parameters
Id- represents the id of a wrap requestsSignature- a base64 encoded ECDSA signature used to redeem funds on the destination network
Returns
- None
UnwrapTokenMethod method
Method for unwrapping assets. It is the first step in redeeming funds on NoM. Normally this method would be called by an orchestrator node after a signing ceremony to register an unwrap request.
Parameters
NetworkClass- the class of the source networkChainId- the chain identifier of the source networkTransactionHash- hash of the transaction on the source networkLogIndex- log index in the block of the transaction that locked/burned the funds on the source network; together withtxHashit creates a unique identifier for a transactionToAddress- destination NoM addressTokenAddress- address of the locked/burned token on the source networkAmount- amount of token that was locked/burnedSignature- the signature asbase64encoded string of the unwrap request
Returns
- None
SetNetworkMethod method
Method for setting a network. Used to add or edit an already existing bridged network.
Parameters
NetworkClass- class of the networkChainId- chain identifier of the networkName-newname of the networkContractAddress-newaddress the bridge contract was deployed toMetadata-JSONencoded string used in case theorchestratorneeds additional data for the network
Returns
- None
RemoveNetworkMethod method
Method for removing a network uniquely identified by its class and chain identifier.
Parameters
NetworkClass- class of the networkChainId- chain identifier of the network
Returns
- None
SetNetworkMetadataMethod method
Method for setting metadata for a network.
Parameters
NetworkClass- class of the networkChainId- chain identifier of the networkMetadata-JSONencoded string containing thenewmetadata
Returns
- None
SetTokenPairMethod method
Method for setting a token pair for a network. It will add a new pair or edit an existing one; guarded by the time challenge primitive.
Parameters
- NetworkClass - network class of the network to add this pair to
- ChainId - chain identifier of the network to add this pair to
- TokenStandard - first component of the pair i.e.
ZTS - TokenAddress - second component of the pair i.e.
EVM-20 Bridgeable- boolean variable that specifies if theZTScan be wrapped on NoMRedeemable- boolean variable that specifies if theEVM-20can be redeemed on NoMOwned- boolean variable that specifies if the embedded bridge contract is the owner of theZTSfrom the pair; if true, when wrapping the ZTS, the token will be burned, otherwise it will be lockedMinAmount- minimum amount for wrapping theZTSFeePercentage- fee deducted from the amount when wrappingRedeemDelay- delay in momentums until redeeming is possible on NoMMetadata-JSONencoded string containing metadata about the pair; used by theorchestrator
Returns
- None
RemoveTokenPairMethod method
Method for removing a token pair for a network.
Parameters
NetworkClass- class of the network that contains the pairChainId- chain identifier of the network that contains the pairTokenStandard-ZTSof the pairTokenAddress-EVM-20address of the pair
Returns
- None
HaltMethod method
Method for halting the bridge. If called by the administrator it doesn't need a signature, otherwise it needs a TSS signature with the current tssNonce.
Parameters
Signature-base64encoded string containing the TSS signature
Returns
- None
UnhaltMethod method
Method for unhalting the bridge. Can be called only by the administrator.
Parameters
- None
Returns
- None
EmergencyMethod method
Method for putting the bridge embedded contract into emergency mode. This method nullifies the administrator address, tss public key and halts the bridge. It can be called in the extreme case when the administrator private key has been compromised.
Parameters
- None
Returns
- None
ChangeTssECDSAPubKeyMethod method
Method for changing the TSS public key. Guarded by time challenge when called by the administrator. Otherwise it can be changed by the TSS using a signature from the current tss, one from the new tss and the new tss public key.
Parameters
PubKey-base64encoded string representing the new TSS public keyOldPubKeySignature-base64encoded string representing thechangeTssmessage signed by the current TSSNewPubKeySignature-base64encoded string representing thechangeTssmessage signed by corresponding private key
Returns
- None
ChangeAdministratorMethod method
Method for changing the admin. Can be called only by the administrator. Guarded by a time challenge with administratorDelay.
Parameters
Address- address of the newadministrator
Returns
- None
SetAllowKeygenMethod method
Method that enables or disables the TSS key generation.
Parameters
Bool-trueorfalsevalue that indicates whether theorchestratornodes should start a key generation ceremony or not
Returns
- None
SetOrchestratorInfoMethod method
Method for setting the information regarding the orchestrator layer.
Parameters
WindowSize- size in momentums of a window used in theorchestratorto determine which signing ceremony should occur, wrap or unwrap request and to determine the key sign ceremony timeoutKeyGenThreshold- minimum number of participants of a key generation ceremonyConfirmationsToFinality- minimum number of momentums to consider a wrap request confirmedEstimatedMomentumTime- time in seconds between momentums
Returns
- None
SetBridgeMetadataMethod method
Method for setting the metadata for the bridge.
Parameters
String-JSONencoded string containing additional information needed for theorchestratorlayer
Returns
- None
RevokeUnwrapRequestMethod method
Method for revoking an unwrap request. This should be called if an unwrap request does not a have corresponding transaction on the source network that locks/burns the tokens.
Parameters
TransactionHash- first component to uniquely identify an unwrap requestLogIndex- second component to uniquely identify an unwrap request
Returns
- None
RedeemMethod method
Method for redeeming assets. It is the second step in order to redeem funds after an unwrap request is created. In order to redeem the unwrap request the following conditions must be present: the bridge must not be halted, the network and token pair must exist and the request have not been redeemed or revoked before.
Parameters
TransactionHash- first component to uniquely identify an unwrap requestLogIndex- second component to uniquely identify an unwrap request
Returns
AccountBlock- if theZTSto be redeemed is owned, an account block to mint the amount will be sent to the token contract, otherwise a block sending the tokens will be sent to the user
NominateGuardiansMethod method
Method for nominating guardians. Can only be called by the administrator in order to propose new guardians. Guarded by a time challenge. The number of guardian addresses must be higher than minGuardians and each address in the array must be unique. ZeroAddress is not accepted.
Parameters
[]Address- contains the new guardian addresses
Returns
- None
ProposeAdministratorMethod method
Method for proposing an admin. This method can only be called by a guardian if the bridge is in emergency mode i.e. the administrator address is set to ZeroAddress. After each guardian votes for an address, the votes are counted and if there is a majority (50% + 1), the administrator will be set with that address.
Parameters
Address- voted address
Returns
- None