SDK
The Brink SDK is a useful tool for developers who want to create and execute upon signed messages.
Installation
The Brink SDK module can be used to interact with Brink proxy accounts, either as the account owner/signer or as an executor of messages signed by the account owner/signer.
Setup
Quick Links: Ethers Library, brink-environment, provider.getSigner(), Signer
Account
Read-only Methods
These methods are available to read from account contract state
Implementation()
Returns the implementation address of the account proxy contract. Should be a deployed instance of Account.sol.
isDeployed()
Returns true if the account has been deployed.
nextBit()
Returns the next valid bit of the account.
loadBitmap()
Loads the bitmap
Transaction Methods
The following methods issue transactions to an account contract. They wrap ethers.js Contract Meta-class methods and can be used in the same way.
The Account instance exposes the ethers.js write method analysis properties estimateGas
, populateTransaction
, and callStatic
. These can be used for any Account transaction. For example, getting transaction data without submitting the transaction can be done like this:
And an example of getting a gas estimate is below:
All of these transactions (except for deploy()
) will include the desired action after account deployment, if the account has not been deployed yet, using DeployAndExecute.sol. If the account is already deployed, the action will be executed directly on the account contract.
sendLimitSwap(limitSwapSignedMessage, to, data)
params:
limitSwapSignedMessage
: a valid signed limit swap message (see AccountSigner methods signEthToTokenSwap()
, signTokenToTokenSwap()
, and signTokenToEthSwap()
)
to
: Address of the contract that will provide liquidity for the fullfilment of the swap
data
: Call data that will be executed on the contract at toAddress
in order to fullfil the swap
Example:
deployment, if the account has not been deployed yet, using DeployAndExecute.sol. If the account is already deployed, the action will be executed directly on the account contract.
cancel(cancelSignedMessage)
params:
cancelSignedMessage
: a valid signed cancel message (see AccountSigner method signCancel()
)
Example:
transferEth(signedEthTransferMessage)
params:
signedEthTransferMessage
: a valid signed eth transfer message (see AccountSigner method signEthTransfer()
)
Example:
transferToken(signedTokenTransferMessage)
params:
signedTokenTransferMessage
: a valid signed token transfer message (see AccountSigner method signTokenTransfer()
)
Example:
deploy()
Deploys the account contract. Throws an error if the contract is already deployed
Example:
externalCall(value, to, data)
Calls externalCall on the account contract.
This can only be called if the ethers.js signer is the owner of the account
Example:
delegateCall(to, data)
Calls delegateCall on the account contract.
This can only be called if the ethers.js signer is the owner of the account
Example:
metaDelegateCall(to, data, signature)
Calls metaDelegateCall on the account contract.
This can only be called with a valid message signed by the owner of the account
Example:
metaPartialSignedDelegateCall(to, data, signature, unsignedData)
Calls metaPartialSignedDelegateCall on the account contract.
This can only be called with a valid message signed by the owner of the account
Example:
AccountSigner
Handles signing of account messages. These authorize actions that can be taken on the account by executors.
Messages are returned in this format:
accountAddress()
Returns the address of the account
signerAddress()
Returns the address of the signer
signEthTransfer(bitmapIndex, bit, recipient, amount, expiryBlock)
Returns a signed metaDelegatedCall
message that allows execution of an ETH transfer
expiryBlock defaults to the max unit256
Verifier function: TransferVerifier.ethTransfer()
signTokenTransfer(bitmapIndex, bit, tokenAddress, recipient, amount, expiryBlock)
Returns a signed metaDelegatedCall
message that allows execution of an ERC20 token transfer
expiryBlock defaults to the max unit256
Verifier function: TransferVerifier.tokenTransfer()
signEthToTokenSwap(bitmapIndex, bit, tokenAddress, ethAmount, tokenAmount, expiryBlock)
Returns a signed metaPartialSignedDelegateCall
message that allows execution of an ETH to ERC20 token swap
expiryBlock defaults to the max unit256
Verifier function: LimitSwapVerifier.ethToToken()
signTokenToEthSwap(bitmapIndex, bit, tokenAddress, tokenAmount, ethAmount, expiryBlock)
Returns a signed metaPartialSignedDelegateCall
message that allows execution of an ERC20 token to ETH swap
expiryBlock defaults to the max unit256
Verifier function: LimitSwapVerifier.tokenToEth()
signTokenToTokenSwap(bitmapIndex, bit, tokenInAddress, tokenOutAddress, tokenInAmount, tokenOutAmount, expiryBlock)
Returns a signed metaPartialSignedDelegateCall
message that allows execution of an ERC20 token to ERC20 token swap
expiryBlock defaults to the max unit256
Verifier function: LimitSwapVerifier.tokenToToken()
signCancel(bitmapIndex, bit)
Returns a signed cancel
message that flips the requested bit of the proxy account
Last updated
Was this helpful?