Skip to content

BSN-Spartan/Multisig-Wallet-Contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

BSN Spartan MultiSig Wallet

Smart Contract

A MultiSig wallet is a digital wallet that operates with multi-signature addresses, and it provides safe and decentralized wallet management in the Spartan Network. The owner of the wallet can initiate and authorize transfers, as well as make changes to other key information.

Prerequisite

Before using this smart contract, it is important to have a basic understanding of Ethereum and Solidity.

Also, the business of this application is based on ERC-20 token transactions. Please refer to ERC-20 Contract to learn how to deploy and use ERC-20 smart contract.

Overview

Usually, a wallet used to store assets is an address generated by a public key. This wallet can be managed by its coressponding private key. Whoever owns this private key is able to dictate the assets held by the wallet. Although single-signature wallets are more convenient to manage, they suffer greater risks than MultiSig wallets.

MultiSig wallets provide a solution by setting up multiple accounts to jointly manage a wallet. The assets in this wallet can be transferred out only after a set number of private keys have signed and agreed, which greatly reduces the risk of asset theft caused by the single signature.

The creation of MultiSig wallets follows "m-of-n" rules, where only after the m holders of the n private keys co-sign and authorize, the wallet can complete the token transfer and other transactions.

Usage

Get the source code of MultiSig wallet contract by command:

$ git clone https://github.com/BSN-Spartan/Multisig-Wallet-Contracts.git

For beginners, the contracts in this application can be deployed by the steps in Spartan Quick Testing.

Follow steps below to deploy and use the smart contract:

  1. Deploy the ERC-20 smart contract. You can refer to ERC-20 Contract to learn how to deploy and use ERC-20 smart contract.
  2. Deploy MultisigWallet.sol contract. When deploying the contract, 3 parameters are needed: owners of the wallet, the number of owners to win the vote, the valid block number for this transaction. For example: _owners: ["0x5B38Da6a701c568545dCfcB03FcB875f56beddC4","0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2","0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db"] _THRESHOLD: 2 _VALIDBLOCKNUMBER: 1000
  3. In ERC-20 smart contract, call mint function to mint tokens, for example 500, to the address of MultisigWallet contract. Then, call balanceOf function and check the balance of the address, which is shown as 500.
  4. In MultisigWallet contract, one owner of the wallet can call initiateTransfer function to initiate a transaction of ERC20 token transfer. Fill in the parameters, including the address of ERC20 contract, the target address to which the tokens will be transferred, the quantity of tokens, and the data in the form of "0x00".
  5. Once executed, the transfer event information can be found in the transaction receipt, including the input information and spendId.
  6. Other owners of the wallet then call approve function to sign and approve for this transfer transaction. The spendId is returned in step 5. The contract will record the number of appoved owners. Once the number reaches the threshold, the tokens will be transferred to the target address.
  7. To add a new owner of the wallet, one of the owners can call createProposal function to raise a voting request. The input parameters are including manageType, which is the proposal type, and its value is 0, temp which is the new threshold, the new owner's address, and data.
  8. After creating the proposal, a proposalId will be returned in the logs of the transaction receipt.
  9. Other owners can call vote function to vote for this proposal and decide whether to allow the new owner to join or not.

Main Functions

initiateTransfer

This function will initiate transfer with a specified amount of assets. The initiator will authorize the transaction by default, and only the wallet owner can be the sender.

Example:

function initiateTransfer(
    address _ERC20Address, 
    address _targetAddress, 
    uint256 _amount, 
    bytes memory _data
)

approve

This function will authorize a transaction of token transfer, and only the wallet owner can be the sender.

Example:

function approve(
    uint256 _spendId, 
    address _targetAddress, 
    address _ERC20Address, 
    uint256 _amount, 
    bytes memory _data
)

revokeTransfer

The function will revoke a transaction of token transfer, and only the wallet owner can be the sender.

Example:

function revokeTransfer(uint256 _spendId)

getOwners

This function will return the list of all wallet owners, and only the wallet owner can be the sender.

Example:

function getOwners() returns(address[])

Expected result:

[
    "0x0",
    "0x0"
]

getSpend

This function will return the transaction information of the token transfer, and only the wallet owner can be the sender.

Example:

function getSpend(uint256 _spendId) returns(
    address sponsor,
    address ERC20Address,
    address targetAddress,
    uint256 amount,
    uint256 expiredBlock,
    address[] memory assentients,
    bytes memory data,
    SpendStatus status
) 

Expected result:

{
    "sponsor": "0x0",
    "ERC20Address": "0x0",
    "targetAddress": "0x0",
    "amount": "1",
    "expiredBlock": "1",
    "assentients": [
        "0x0",
        "0x0"
    ],
    "data": "1",
    "status": 1
}

getThreshold

This function will return the value of threshold that agrees the transaction, and only the wallet owner can be the sender.

Example:

function getThreshold() returns(uint256)

Expected result:

{
    "threshold": 1
}

getValidBlockNumber

This function will return the valid date, and only the wallet owner can be the sender.

Example:

function getValidBlockNumber() returns(uint256)

Expected result:

{
    "threshold": 1
}

checkAddr

This function will check whether the address is the wallet owner, and only the wallet owner can be the sender.

Example:

function checkAddr(address addr) returns(bool)

Expected result:

{
    "checkAddr": true
}

createProposal

This function will create a proposal, including adding the wallet owner, delete the wallet owner, change the valid date, change the number of threshold, and only the wallet owner can be the sender.

Example:

function createProposal(
    ManageFunctionType _manageType, 
    address _owner, 
    uint256 _temp, 
    bytes memory _data
)

vote

This function will vote for a proposal, and only the wallet owner can be the sender.

Example:

function vote(
    uint256 _proposalId, 
    bool _decision, 
    bytes memory _data
)

getProposal

This function will return the specified proposal information, and only the wallet owner can be the sender.

Example:

function getProposal(uint256 _proposalId) public view onlyOwner returns(
        address sponsor,
        address owner,
        uint256 temp,
        ManageFunctionType manageType,
        bytes memory data,
        uint256 expiredBlock,
        ProposalStatus status,
	    address[] memory assentients
)

Expected result:

{
    "sponsor": "0x0",
    "owner": "0x0",
    "temp": 1,
    "manageType": 1,
    "data": "1",
    "expiredBlock": 1,
    "status": 1,
    "assentients": [
        "0x0",
        "0x0"
    ]
}

getProposalAssentients

This function will return a list of valid votes for the specified proposal, and only the wallet owner can be the sender.

Example:

function getProposalAssentients(uint256 _proposalId) returns(address[] memory assentients)

Expected result:

[
    "0x0",
    "0x0"
]

License

Spartan-MultiSig Wallet Contract is released under the Spartan License.

Releases

No releases published

Packages

No packages published