dao代幣質押流動性挖礦開發正式版丨dao代幣質押流動性挖礦系統開發案例詳細及原始碼

xiaofufu發表於2023-03-15

  Uniswap V1中ERC20代幣的相互兌換主要是以ETH為中介進行,也就是說其中一種ERC20代幣兌換成ETH,再由ETH兌換成目標ERC20代幣


  #notice Convert Tokens(self.token)to Tokens(token_addr).


  #dev User specifies exact input and minimum output.


#param tokens_sold Amount of Tokens sold.支付的代幣數量


  #param min_tokens_bought Minimum Tokens(token_addr)purchased.購買的代幣的最小值


  #param min_eth_bought Minimum ETH purchased as intermediary.作為中介的ETH的最小值


  #param deadline Time after which this transaction can no longer be executed.


  #param token_addr The address of the token being purchased.目標代幣的ERC20合約地址


  #return Amount of Tokens(token_addr)bought.最終購買的代幣數量


  #根據輸入的代幣數量兌換相應數量的目標代幣


  關於區塊鏈專案技術開發唯:MrsFu123,代幣發行、dapp智慧合約開發、鏈遊開發、多鏈錢包開發


  交易所開發、量化合約開發、互助遊戲開發、Nft數字藏品開發、眾籌互助開發、元宇宙開發、swap開發、


  鏈上合約開發、ido開發、商城開發等,開發過各種各樣的系統模式,更有多種模式、制度、案例、後臺等,成熟技術團隊,歡迎實體參考。


  public


  def tokenToTokenSwapInput(tokens_sold:uint256,min_tokens_bought:uint256,min_eth_bought:uint256(wei),deadline:timestamp,token_addr:address)->uint256:


  #獲得目標代幣的兌換合約地址


  exchange_addr:address=self.factory.getExchange(token_addr)


  return self.tokenToTokenInput(tokens_sold,min_tokens_bought,min_eth_bought,deadline,msg.sender,msg.sender,exchange_addr)


  


  #notice Convert Tokens(self.token)to Tokens(token_addr)and transfers


  #Tokens(token_addr)to recipient.


  #dev User specifies exact input and minimum output.


  #param tokens_sold Amount of Tokens sold.支付的代幣數量


  #param min_tokens_bought Minimum Tokens(token_addr)purchased.購買的代幣的最小值


  #param min_eth_bought Minimum ETH purchased as intermediary.作為中介的ETH的最小值


  #param deadline Time after which this transaction can no longer be executed.


  #param recipient The address that receives output ETH.目標代幣的接收者地址


  #param token_addr The address of the token being purchased.目標代幣的ERC20合約地址


  #return Amount of Tokens(token_addr)bought.最終購買的代幣數量


  #根據輸入的代幣數量兌換相應數量的目標代幣,並將目標代幣傳送給指定接收者


  public


  def tokenToTokenTransferInput(tokens_sold:uint256,min_tokens_bought:uint256,min_eth_bought:uint256(wei),deadline:timestamp,recipient:address,token_addr:address)->uint256:


  exchange_addr:address=self.factory.getExchange(token_addr)


  return self.tokenToTokenInput(tokens_sold,min_tokens_bought,min_eth_bought,deadline,msg.sender,recipient,exchange_addr)


  


  #notice Convert Tokens(self.token)to Tokens(token_addr).


  #dev User specifies maximum input and exact output.


  #param tokens_bought Amount of Tokens(token_addr)bought.所要購買的代幣數量


  #param max_tokens_sold Maximum Tokens(self.token)sold.所要支付的代幣的最大值


  #param max_eth_sold Maximum ETH purchased as intermediary.作為中介的ETH的最大值


  #param deadline Time after which this transaction can no longer be executed.


  #param token_addr The address of the token being purchased.目標代幣的ERC20合約地址


  #return Amount of Tokens(self.token)sold.最終所需要支付的代幣數量


  #根據所要購買的目標代幣數量支付相應數量的持有代幣


  public


  def tokenToTokenSwapOutput(tokens_bought:uint256,max_tokens_sold:uint256,max_eth_sold:uint256(wei),deadline:timestamp,token_addr:address)->uint256:


  exchange_addr:address=self.factory.getExchange(token_addr)


  return self.tokenToTokenOutput(tokens_bought,max_tokens_sold,max_eth_sold,deadline,msg.sender,msg.sender,exchange_addr)


  


  #notice Convert Tokens(self.token)to Tokens(token_addr)and transfers


  #Tokens(token_addr)to recipient.


  #dev User specifies maximum input and exact output.


  #param tokens_bought Amount of Tokens(token_addr)bought.所要購買的代幣數量


  #param max_tokens_sold Maximum Tokens(self.token)sold.所要支付的代幣的最大值


  #param max_eth_sold Maximum ETH purchased as intermediary.作為中介的ETH的最大值


  #param deadline Time after which this transaction can no longer be executed.


  #param recipient The address that receives output ETH.目標代幣的接收者地址


  #param token_addr The address of the token being purchased.目標代幣的ERC20合約地址


  #return Amount of Tokens(self.token)sold.最終所需要支付的代幣數量


  #根據所要購買的目標代幣數量支付相應數量的持有代幣,並將所兌換的目標代幣傳送給指定接收者


  public


  def tokenToTokenTransferOutput(tokens_bought:uint256,max_tokens_sold:uint256,max_eth_sold:uint256(wei),deadline:timestamp,recipient:address,token_addr:address)->uint256:


  exchange_addr:address=self.factory.getExchange(token_addr)


  return self.tokenToTokenOutput(tokens_bought,max_tokens_sold,max_eth_sold,deadline,msg.sender,recipient,exchange_addr)


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69956839/viewspace-2939876/,如需轉載,請註明出處,否則將追究法律責任。

相關文章