Add atomic DODO seeding helper
Some checks failed
CI/CD Pipeline / Solidity Contracts (push) Failing after 1m6s
CI/CD Pipeline / Security Scanning (push) Successful in 2m34s
CI/CD Pipeline / Lint and Format (push) Failing after 37s
CI/CD Pipeline / Terraform Validation (push) Failing after 22s
CI/CD Pipeline / Kubernetes Validation (push) Successful in 21s
Validation / validate-genesis (push) Successful in 33s
Validation / validate-terraform (push) Failing after 29s
Validation / validate-kubernetes (push) Failing after 11s
Validation / validate-smart-contracts (push) Failing after 12s
Validation / validate-security (push) Failing after 58s
Validation / validate-documentation (push) Failing after 19s
OMNL reconcile anchor / Run omnl:reconcile and upload artifacts (push) Failing after 23s
Verify Deployment / Verify Deployment (push) Failing after 49s
Some checks failed
CI/CD Pipeline / Solidity Contracts (push) Failing after 1m6s
CI/CD Pipeline / Security Scanning (push) Successful in 2m34s
CI/CD Pipeline / Lint and Format (push) Failing after 37s
CI/CD Pipeline / Terraform Validation (push) Failing after 22s
CI/CD Pipeline / Kubernetes Validation (push) Successful in 21s
Validation / validate-genesis (push) Successful in 33s
Validation / validate-terraform (push) Failing after 29s
Validation / validate-kubernetes (push) Failing after 11s
Validation / validate-smart-contracts (push) Failing after 12s
Validation / validate-security (push) Failing after 58s
Validation / validate-documentation (push) Failing after 19s
OMNL reconcile anchor / Run omnl:reconcile and upload artifacts (push) Failing after 23s
Verify Deployment / Verify Deployment (push) Failing after 49s
This commit is contained in:
47
contracts/dex/DODOAtomicSeeder.sol
Normal file
47
contracts/dex/DODOAtomicSeeder.sol
Normal file
@@ -0,0 +1,47 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
interface IERC20AtomicSeeder {
|
||||
function transferFrom(address from, address to, uint256 amount) external returns (bool);
|
||||
}
|
||||
|
||||
interface IDODOAtomicSeedPool {
|
||||
function buyShares(address to) external returns (uint256 baseShare, uint256 quoteShare, uint256 lpShare);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title DODOAtomicSeeder
|
||||
* @notice Pulls both DODO DVM seed tokens and mints LP shares in one transaction.
|
||||
* @dev This avoids exposing half-seeded pools between separate ERC-20 transfers.
|
||||
*/
|
||||
contract DODOAtomicSeeder {
|
||||
error TransferFromFailed(address token);
|
||||
error ZeroAddress();
|
||||
|
||||
function seed(
|
||||
address pool,
|
||||
address baseToken,
|
||||
address quoteToken,
|
||||
uint256 baseAmount,
|
||||
uint256 quoteAmount,
|
||||
address recipient
|
||||
) external returns (uint256 baseShare, uint256 quoteShare, uint256 lpShare) {
|
||||
if (pool == address(0) || baseToken == address(0) || quoteToken == address(0) || recipient == address(0)) {
|
||||
revert ZeroAddress();
|
||||
}
|
||||
|
||||
_safeTransferFrom(baseToken, msg.sender, pool, baseAmount);
|
||||
_safeTransferFrom(quoteToken, msg.sender, pool, quoteAmount);
|
||||
return IDODOAtomicSeedPool(pool).buyShares(recipient);
|
||||
}
|
||||
|
||||
function _safeTransferFrom(address token, address from, address to, uint256 amount) internal {
|
||||
if (amount == 0) return;
|
||||
(bool ok, bytes memory data) = token.call(
|
||||
abi.encodeWithSelector(IERC20AtomicSeeder.transferFrom.selector, from, to, amount)
|
||||
);
|
||||
if (!ok || (data.length != 0 && !abi.decode(data, (bool)))) {
|
||||
revert TransferFromFailed(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user