Whitelabel

These docs will guide you on how to interact with our smart contract trading service at the Web3, blockchain-level with examples given in Solidity.

We would be honoured if you chose to integrate our service into your DeFi project. Please do drop us a line if you integrate! We would happily promote your integration: contact@trendespresso.com​

From a top-level view, funds are moved in the following order: Your Wallet -> BotDepositWithdraw -> Your BotPrivate.

Funds being withdrawn are moved directly from your smart contract wallet (BotPrivate) to Your Wallet. Balances cannot be transferred to any other address. Withdrawals can only be sent back to the depositing address.


BotDepositWithdraw

Required for depositing or withdrawing.

Solidity Example Code

  • deposit() transaction

  • withdraw() transaction (pending if there's an active trade)

  • withdrawNow() transaction (always immediate)

import "./IERC20.sol";
import "./IBotDepositWithdraw.sol";
IERC20 constant usdc = IERC20(0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E);
IBotDepositWithdraw constant teBot = IBotDepositWithdraw(0x000000);

function deposit(uint amount) external {
    // do some things
    // we will write more in the future!
}

function withdraw(uint amount) external {
    // do some other things
    // we promise to write more in the future!
}

Solidity Interface (IERC20.sol): https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol

Solidity Interface (IBotDepositWithdraw.sol): https://github.com/

Solidity contract full source code (BotDepositWithdraw.sol): https://github.com/

The above code deposits and withdraws 0.


Balance Check

If you'd like to check your balance, you'll need a bit more code. Please note that checking your balance during a trade will return a best guess estimate using Chainlink's quoted USD prices for the asset token. Your BotPrivate will hold asset tokens (in a Long position) and/or may owe them as debt (in a Short position) which is subtracted from the cash token holdings to arrive at the final balance. There's two methods by which you may check your current balance. To include this functionality, add your preferred function call to the Solidity example code above:

function getMyBalance() external view returns (uint) {
    return BotDepositWithdraw.getCurrentBalance().current;
}

// More to write in the future!

Deposit

The deposit() function will transferFrom() the depositor the amountCash registered in BotPool's cash tokens. These tokens will only be successfully transferred if they are accepted into the Trading Bot. The deposit() function will revert if the depositor's internal balance did not increase. The deposit() function requires sufficient allowance to transferFrom() the depositor. An approve() transaction must be executed on the USDC token contract first: https://github.com/centrehq/centre-tokens/blob/master/contracts/v1/FiatTokenV1.sol#L226​Scenario: The botprivate contract has an active trade and a depositor has a Pending Withdrawal of 10 USDC. If the depositor submits a deposit()of 3 USDC, then no USDC will be transferred. Instead, their Pending Withdrawal will be amended to 7 USDC.Note that USDC is the only cash token used during Alpha v2.5. The USDC deposited will be held temporarily in the BotPool contract if the botprivate contract has an active trade. Otherwise, USDC will be deposited directly into the botprivate contract if it has no active trade ("holding cash").Deposits made during an active trade will be accepted on the active trade's exit. Until then, the USDC tokens will be held in the BotPool contract as a Pending Deposit.The minimum deposit, and balance, during Alpha v2.5 is 1 USDC. Balances that fall below 1 USDC on trade exit will be withdrawn to the depositor.function deposit(address botPool, uint amountTE, uint amountCash)​

https://github.com/​


Deposit (with gasless approvals)

The depositWithPermit function only offers execution of gasless EIP-2612 Permits for depositing tokens. Unless you really nerd out on that kind of stuff, this is not relevant for Alpha v2.5 (current version).function depositWithPermit(address botPool,uint amountTE,uint amountCash,uint toApprove,uint deadline,uint8 v,bytes32 r,bytes32 s)​

https://github.com/​


Withdraw (Standard, Pending)

The withdraw() function executes a withdrawal immediately if the botprivate contract has no active trade or submits a Pending Withdrawal if the botprivate contract has an active trade. In the case of a Pending Withdrawal, the withdrawal will be processed on trade exit at the same time as Pending Deposits. A depositor may not concurrently have a Pending Withdrawal and Pending Deposit as they are exclusive to each other.Scenario: The botprivate contract has an active trade and a depositor has a Pending Deposit of 10 USDC. If the depositor requests a withdraw()of 3 USDC, then they will instantly receive 3 USDC and have their Pending Deposit amended to 7 USDC.If there is an active trade, the amount you request to withdraw() may put your balance below the 1 USDC required minimum balance by the time the trade exits. In such a scenario, your request will instead be processed by withdrawAll() and your full balance will be returned.Since these withdrawals occur only when the botprivate contract has settled its trade into cash tokens, there is no slippage and no additional on-chain fees.function withdraw(address botPool, uint amountEC, uint amountCash)​

https://github.com/​


Withdraw (Immediate)

The withdrawNow() function immediately withdraws the given TE and cash tokens with an optional swapCallData field submitted to 0x's smart contracts. To obtain the swapCallData, an 0x API call must be made in Web2 for subsequent submission into Web3. Since submitting an 0x API call is complicated and requires unique authorisation using an API token, please contact us for further guidance if you desire to implement immediate withdrawals: contact@trendespresso.com​

Full withdrawals must be submitted using either the withdrawAll() or withdrawAllNow() function. The standard withdraw() and withdrawNow() functions only allow for partial withdrawals.Generally speaking up to 90% of your balance can be partially withdrawn. Keep in mind that 1 USDC is the required minimum balance.This is an irreversible transaction which instantly reduces your balance in the Trading Bot and settles your requested portion of the Trading Bot's position into cash tokens. High slippage may occur due to on-chain swapping!If there is an active trade, on-chain slippage could consume a large portion of your balance! Our frontend at https://app.trendespresso.com verifies slippage and reports an estimate before transaction submission whereas no such functionality exists directly on the blockchain, contract-to-contract.function withdrawNow(address botPrivate,uint amountTE,uint amountCash,bytes calldata swapCallData)

​https://github.com/​


Withdraw All (Standard, Pending)

The withdrawAll() function will withdraw your entire position. This will execute immediately if there is no active trade or setup a Pending Withdrawal for your full balance if an active trade exists.After submitting a withdrawAll() request, new withdraw() requests – which withdraw only part of your balance – will be denied (revert with a reason string). To learn how to cancel your withdrawAll() request, see Cancel Pending Transfers.Since these withdrawals occur only when the botprivate contract has settled its trade into cash tokens, there is no slippage and no additional on-chain fees.function withdrawAll(address botPrivate, bool onlyCash)

​https://github.com/​


Withdraw All (Immediate)

The withdrawAllNow() function will withdraw your entire position immediately. This will execute regardless of active trade status. In the case of no active trade existing, this operates the same way as the standard withdrawAll() function.If there is an active trade, the optional swapCallData field executes the required swap via 0x's smart contracts. To obtain the swapCallData, an 0x API call must be made in Web2 for subsequent submission into Web3. Since submitting an 0x API call is complicated and requires unique authorisation using an API token, please contact us for further guidance if you desire to implement immediate withdrawals: contact@trendespresso.com​

This is an irreversible transaction which eliminates your entire balance in the Trading Bot and settles your entire portion of the Trading Bot's position. High slippage may occur due to on-chain swapping!If there is an active trade, on-chain slippage could consume a large portion of your balance! Our frontend at https://app.trendespresso.com verifies slippage and reports an estimate before transaction submission whereas no such functionality exists directly on the blockchain, contract-to-contract.function withdrawAllNow(address botPrivate,bool onlyCash,bytes calldata swapCallData)

​https://github.com


Cancel Pending Transfers

You may cancel your withdrawAll() request and all other Pending transfers of cash tokens by executing the cancelPendingTransfers() function on the Frontend contract. Executing this function will immediately cancel all Pending Deposits and Pending Withdrawals including a pending withdrawAll() request.To include this functionality, add the following to the Solidity example code above:function cancelPendingTransfers() external {// instantly cancels all pending deposits and pending withdrawalsFrontend.cancelPendingTransfers(botPrivate);}​

https://github.com/​​​

Last updated