Integrate your own DCA primitive directly for your Madara App Chain.
Modify your node so that it does the following action:
You need a runtime API that allows your node to fetch the current batch index and the pending_dca_ids from the smart contract.
Retreive the pending_dca_ids by interacting with the smart contract's storage or by calling get_current_batch_index & get_pending_dca_ids.
For each dca_id in pending_dca_ids, create a transaction that calls the execute function on the smart contract with the dca_id as argument.
With a custom proposer, insert the constructed transactions at the beginning of the block during block production and ensure the transactions are valid according to your runtime's rules.
This logic can be implemented to execute at the beginning of each block to ensure DCA are executed at the correct timestamp.
Edit the interface of IDex 7 IPriceOracle in the file interface.cairo and adapt the lines 307-312.
let oracle = IPriceOracleDispatcher { contract_address: self.oracle_address.read() };
let price: u256 = oracle.get_price(source_asset, target_asset, amount).into();
let slippage: u256 = 50_u256; // 0.5%
let min_out = (price * (10000_u256 - slippage)) / 10000_u256;
let dex = IDexDispatcher { contract_address: self.dex_address.read() };
let received: u256 = dex.swap(amount, source_asset, target_asset, min_out).into();If the DEX doesn't require the fund to be previously sent to the DEX smart contract, edit the lines 299-304 to adapt to your mechanism.
let erc_in = IERC20Dispatcher { contract_address: source_asset };
let bal: u256 = erc_in.balance_of(owner).into();
assert(bal >= amount, 'INSUFFICIENT_FUNDS');
let allowance: u256 = erc_in.allowance(owner, get_contract_address()).into();
assert(allowance >= amount, 'INSUFFICIENT_ALLOWANCE');
erc_in.transfer_from(owner, get_contract_address(), amount);Deploy the DCA smart-contract and initialize it with the correct addresses:
- operator: Address linked to the node calling the
executefunction - dex_address: Address of the DEX the DCA is performed on
- oracle_address: Address of the price oracle