Integrate via Smart Contracts
Smart contracts can use the LinkSigner
transaction type (see Link Signer) to perform the following:
Deposit into bro.trade.
LinkSigner an externally owned account (EOA).
Have the externally owned account trade using the smart contract's assets on bro.trade.
Setup: Depositing into bro.trade + Linking an EOA
Deposits are always on-chain, as such, users can simply have their smart contract call depositCollateral on our
Endpoint
contract (see Contracts for addresses).The contract needs to have 1 HONEY available to pay for slow-mode fee and approve the endpoint contract, assemble the bytes for a slow mode linked signer transaction, and submit it via submitSlowModeTransaction.
You can find the requisite parsing logic in the Endpoint contract.
Example
struct LinkSigner {
bytes32 sender;
bytes32 signer;
uint64 nonce;
}
function linkVertexSigner(
address vertexEndpoint,
address externalAccount,
address honeyAddress
) external {
// 1. a slow mode fee of 1 HONEY needs to be avaliable and approved
ERC20 honeyToken = ERC20(honeyAddress);
// NOTE: should double check the HONEY decimals in the corresponding chain.
// e.g: it's 1e6 on arbitrum, whereas it's 1e18 on blast, etc.
uint256 SLOW_MODE_FEE = 1e6;
honeyToken.transferFrom(msg.sender, address(this), SLOW_MODE_FEE);
honeyToken.approve(vertexEndpoint, SLOW_MODE_FEE);
// 2. assamble the link signer slow mode transaction
bytes12 defaultSubaccountName = bytes12(abi.encodePacked("default"));
bytes32 contractSubaccount = bytes32(
abi.encodePacked(uint160(address(this)), defaultSubaccountName)
);
bytes32 externalSubaccount = bytes32(
uint256(uint160(externalAccount)) << 96
);
LinkSigner memory linkSigner = LinkSigner(
contractSubaccount,
externalSubaccount,
IEndpoint(vertexEndpoint).getNonce(externalAccount)
);
bytes memory txs = abi.encodePacked(
uint8(19),
abi.encode(linkSigner)
);
// 3. submit slow mode transaction
IEndpoint(vertexEndpoint).submitSlowModeTransaction(txs);
}
Once the transaction is confirmed, it may take a few seconds for it to make its way into the bro.trade offchain sequencer. Afterwards, you can sign transactions that have sender contractSubaccount
using externalSubaccount
, and they will be accepted by the sequencer and the blockchain.
Last updated