文章
问答
讲堂
百科图谱
线下集训
更多
提问
发表文章
专栏
活动
文档
工作
集市
发现
Toggle navigation
文章
问答
讲堂
线下集训
专栏
活动
工作
文档
集市
搜索
登录/注册
5
要实现第一次流动性添加只能由管理者操作,并且添加完流动性抢跑的拉黑。
回答问题即可获得
5
贡献值,回答被采纳后即可获得
10
学分。
![image.png](https://img.learnblockchain.cn/attachments/2022/05/KqMn4RsE628c5006c1438.png) ![image.png](https://img.learnblockchain.cn/attachments/2022/05/WTmmCxsK628c4d877ef6b.png)
0 条评论
分类:
以太坊
请先
登录
后评论
默认排序
时间排序
1 个回答
如笛
2022-05-24 20:55
不一定要拉黑,参考下这个: interface IUniswapV2Pair { function token0() external view returns (address); ``` function token1() external view returns (address); ``` } contract LiquidityRestrictor is Ownable { struct Parameters { bool bypass; mapping(address => bool) isInitializer; mapping(address => uint256) startedAt; mapping(address => bool) isLocalAgent; } mapping(address => Parameters) public parameters; mapping(address => bool) public isTrustedAgent; ``` event SetBypass(address indexed token, bool bypassed); event SetInitializer(address indexed token, address indexed who, bool isInitializer); event SetLocalAgent(address indexed token, address indexed who, bool isLocalAgent); event SetTrustedAgent(address indexed who, bool isTrustedAgent); event Started(address indexed token, address indexed pair, uint256 timestamp); function setParameters( address token, address[] memory initializers, address[] memory localAgents ) external onlyOwner { setInitializers(token, initializers, true); setLocalAgents(token, localAgents, true); } function setBypass(address token, bool bypass) external onlyOwner { parameters[token].bypass = bypass; emit SetBypass(token, bypass); } function setInitializers( address token, address[] memory who, bool isInitializer ) public onlyOwner { for (uint256 i = 0; i < who.length; i++) { parameters[token].isInitializer[who[i]] = isInitializer; emit SetInitializer(token, who[i], isInitializer); } } function setLocalAgents( address token, address[] memory who, bool isLocalAgent ) public onlyOwner { for (uint256 i = 0; i < who.length; i++) { parameters[token].isLocalAgent[who[i]] = isLocalAgent; emit SetLocalAgent(token, who[i], isLocalAgent); } } function setTrustedAgents(address[] memory who, bool isTrustedAgent_) external onlyOwner { for (uint256 i = 0; i < who.length; i++) { isTrustedAgent[who[i]] = isTrustedAgent_; emit SetTrustedAgent(who[i], isTrustedAgent_); } } function assureByAgent( address token, address from, address to ) external returns (bool allow, string memory message) { if (!(isTrustedAgent[msg.sender] || parameters[token].isLocalAgent[msg.sender])) return (false, 'LR: not agent'); return _assureLiquidityRestrictions(token, from, to); } function assureLiquidityRestrictions(address from, address to) external returns (bool allow, string memory message) { return _assureLiquidityRestrictions(msg.sender, from, to); } function _assureLiquidityRestrictions( address token, address from, address to ) internal returns (bool allow, string memory message) { Parameters storage params = parameters[token]; if (params.startedAt[to] > 0 || params.bypass || !checkPair(token, to)) return (true, ''); if (!params.isInitializer[from]) return (false, 'LR: unauthorized'); params.startedAt[to] = block.timestamp; emit Started(token, to, block.timestamp); return (true, 'start'); } function checkPair(address token, address possiblyPair) public view returns (bool isPair) { try this._checkPair(token, possiblyPair) returns (bool value) { if (token == address(0)) return true; return value; } catch { return false; } } function _checkPair(address token, address possiblyPair) public view returns (bool isPair) { address token0 = IUniswapV2Pair(possiblyPair).token0(); address token1 = IUniswapV2Pair(possiblyPair).token1(); return token0 == token || token1 == token; } function seeRights(address token, address who) public view returns ( bool isInitializer, bool isLocalAgent, bool isTrustedAgent_ ) { return (parameters[token].isInitializer[who], parameters[token].isLocalAgent[who], isTrustedAgent[who]); } function seeStart(address token, address pair) public view returns (uint256 startedAt) { return parameters[token].startedAt[pair]; } ``` }
请先
登录
后评论
您需要登录后才可以回答问题,
登录
关注
3
关注
收藏
0
收藏,
2510
浏览
王long
提出于 2022-05-24 11:27
×
发送私信
请将文档链接发给晓娜,我们会尽快安排上架,感谢您的推荐!
发给:
内容:
×
举报此文章
垃圾广告信息:
广告、推广、测试等内容
违规内容:
色情、暴力、血腥、敏感信息等内容
不友善内容:
人身攻击、挑衅辱骂、恶意行为
其他原因:
请补充说明
举报原因: