def __init__(self): super().__init__() self.base_token = ERC20Token(web3=self.web3, address=ERC20Token.token_address_by_name( self.arguments.base_token)) self.min_profit = Wad.from_number(self.arguments.min_profit) self.max_engagement = Wad.from_number(self.arguments.max_engagement) if len(self.arguments.excluded_makers) > 0: self.excluded_makers = set( map(lambda maker: Address(maker), self.arguments.excluded_makers.split(','))) else: self.excluded_makers = set() self.max_errors = self.arguments.max_errors self.errors = 0 if self.arguments.tx_manager: self.tx_manager_address = Address(self.arguments.tx_manager) self.tx_manager = TxManager(web3=self.web3, address=self.tx_manager_address) if self.tx_manager.owner() != self.our_address: logging.info( f"The TxManager has to be owned by the address the keeper is operating from." ) exit(-1) else: self.tx_manager_address = None self.tx_manager = None
def __str__(self): def amt(amount: Wad) -> str: return f"{amount} " if amount is not None else "" source_token_name = ERC20Token.token_name_by_address(self.source_token) target_token_name = ERC20Token.token_name_by_address(self.target_token) return f"[{amt(self.source_amount)}{source_token_name} -> {amt(self.target_amount)}{target_token_name} " \ f"@{self.rate} by {self.method} (max={self.max_source_amount} {source_token_name})]"
def __init__(self, auction_manager, auction_id, auction_info): self._auction_manager = auction_manager self.auction_id = auction_id self.creator = Address(auction_info[0]) self.selling = ERC20Token(web3=auction_manager.web3, address=Address(auction_info[1])) self.buying = ERC20Token(web3=auction_manager.web3, address=Address(auction_info[2])) self.start_bid = Wad(auction_info[3]) self.min_increase = auction_info[4] self.min_decrease = auction_info[5] self.sell_amount = Wad(auction_info[6]) self.ttl = auction_info[7] self.reversed = auction_info[8] self.unsold = auction_info[9]
def __init__(self, lpc: Lpc): self.lpc = lpc rate = Ray(self.lpc.par() / (self.lpc.tag() * self.lpc.gap())) #TODO we always leave 0.000001 in the liquidity pool, in case of some rounding errors max_entry_ref = Wad.max((ERC20Token(web3=lpc.web3, address=lpc.alt()).balance_of(lpc.address) / Wad(rate)) - Wad.from_number(0.000001), Wad.from_number(0)) super().__init__(source_token=self.lpc.ref(), target_token=self.lpc.alt(), rate=rate, max_source_amount=max_entry_ref, method="lpc.take(alt)")
def test_equals(self): # given token1 = DSToken.deploy(self.web3, 'ABC') token2 = DSToken.deploy(self.web3, 'DEF') token2b = ERC20Token(web3=self.web3, address=token2.address) # expect assert token1 == token1 assert token2 == token2b assert not token1 == token2 assert not token1 == token2b
def __init__(self): super().__init__() self.tub_address = Address(self.config.get_contract_address("saiTub")) self.tub = Tub(web3=self.web3, address=self.tub_address) self.tap_address = Address(self.config.get_contract_address("saiTap")) self.tap = Tap(web3=self.web3, address=self.tap_address) self.top_address = Address(self.config.get_contract_address("saiTop")) self.top = Top(web3=self.web3, address=self.top_address) self.otc_address = Address(self.config.get_contract_address("otc")) self.otc = SimpleMarket(web3=self.web3, address=self.otc_address) self.skr = ERC20Token(web3=self.web3, address=self.tub.skr()) self.sai = ERC20Token(web3=self.web3, address=self.tub.sai()) self.gem = DSEthToken(web3=self.web3, address=self.tub.gem()) ERC20Token.register_token(self.tub.skr(), 'SKR') ERC20Token.register_token(self.tub.sai(), 'SAI') ERC20Token.register_token(self.tub.gem(), 'WETH')
parser.add_argument( "--step", help="Incremental step towards the maximum price (value between 0 and 1)", required=True, type=float) args = parser.parse_args() web3 = Web3( HTTPProvider(endpoint_uri=f"http://{args.rpc_host}:{args.rpc_port}")) web3.eth.defaultAccount = args.eth_from #TODO allow to use ETH_FROM env variable config = Config(web3) auction_manager_address = Address( config.get_contract_address("auctionManager")) auction_manager = AuctionManager(web3=web3, address=auction_manager_address, is_splitting=True) trader_address = Address(args.eth_from) dai_address = ERC20Token.token_address_by_name("DAI") dai_token = ERC20Token(web3=web3, address=dai_address) mkr_address = ERC20Token.token_address_by_name("MKR") mkr_token = DSToken(web3=web3, address=mkr_address) strategy = BasicForwardAuctionStrategy( dai_token, mkr_token, args.mkr_dai_rate, args.step, Wad(args.minimal_mkr_bid * 1000000000000000000)) engine = AuctionEngine(auction_manager, trader_address, strategy, args.frequency) engine.start()
from web3 import HTTPProvider from web3 import Web3 from api import Address from api.token import ERC20Token from api.numeric import Wad from api.sai import Tub web3 = Web3(HTTPProvider(endpoint_uri=f"http://localhost:8545")) web3.eth.defaultAccount = "0x002ca7F9b416B2304cDd20c26882d1EF5c53F611" our_address = Address(web3.eth.defaultAccount) destination_address = Address("0x0061f1dbAf1e1B2E412A75D3eD6B48c3D7412D35") tub = Tub(web3=web3, address=Address('0xc349a197c9c3200411094adec82972a2b921c6e2')) sai = ERC20Token(web3=web3, address=tub.sai()) print(f"Source balance before the transfer is {sai.balance_of(our_address)} SAI") print(f"Destination balance before the transfer is {sai.balance_of(destination_address)} SAI") print(f"") print(f"Attempting to transfer 10 SAI...") if sai.transfer(destination_address, Wad.from_number(10)): print(f"Transfer was successful") print(f"") print(f"Source balance after the transfer is {sai.balance_of(our_address)} SAI") print(f"Destination balance after the transfer is {sai.balance_of(destination_address)} SAI") else: print(f"Transfer failed. Check if you have enough SAI balance.")
# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from web3 import HTTPProvider from web3 import Web3 from api import Address from api.token import ERC20Token from api.numeric import Ray from api.sai import Tub, Lpc web3 = Web3(HTTPProvider(endpoint_uri=f"http://localhost:8545")) tub = Tub(web3=web3, address=Address('0xc349a197c9c3200411094adec82972a2b921c6e2')) sai = ERC20Token(web3=web3, address=tub.sai()) skr = ERC20Token(web3=web3, address=tub.skr()) gem = ERC20Token(web3=web3, address=tub.gem()) lpc = Lpc(web3=web3, address=Address('0x421943ce89b6d0daf0128aafc679079050aa0c1e')) print(f"") print(f"Token summary") print(f"-------------") print(f"SAI total supply : {sai.total_supply()} SAI") print(f"SKR total supply : {skr.total_supply()} SKR") print(f"GEM total supply : {gem.total_supply()} GEM") print(f"") print(f"Collateral summary") print(f"------------------") print(f"GEM collateral : {tub.pie()} GEM")
def approve(self, approval_function): approval_function(ERC20Token(web3=self.web3, address=self.ref()), self.address, 'Lpc') approval_function(ERC20Token(web3=self.web3, address=self.alt()), self.address, 'Lpc')
def approve(self, approval_function): approval_function(ERC20Token(web3=self.web3, address=self.gem()), self.jar(), 'Tub.jar') approval_function(ERC20Token(web3=self.web3, address=self.skr()), self.jar(), 'Tub.jar') approval_function(ERC20Token(web3=self.web3, address=self.sai()), self.pot(), 'Tub.pot') approval_function(ERC20Token(web3=self.web3, address=self.skr()), self.pit(), 'Tub.pit') approval_function(ERC20Token(web3=self.web3, address=self.sai()), self.pit(), 'Tub.pit')
def test_token_registry(self): # given ERC20Token.register_token(Address('0x0100000000000000000000000000000000000000'), 'ABC') ERC20Token.register_token(Address('0x0200000000000000000000000000000000000000'), 'DEF') ERC20Token.register_token(Address('0x0300000000000000000000000000000000000000'), 'GHI') # expect assert ERC20Token.token_name_by_address(Address('0x0100000000000000000000000000000000000000')) == 'ABC' assert ERC20Token.token_name_by_address(Address('0x0200000000000000000000000000000000000000')) == 'DEF' assert ERC20Token.token_name_by_address(Address('0x0300000000000000000000000000000000000000')) == 'GHI' with pytest.raises(Exception): assert ERC20Token.token_name_by_address(Address('0x0400000000000000000000000000000000000000')) # and assert ERC20Token.token_address_by_name('ABC') == Address('0x0100000000000000000000000000000000000000') assert ERC20Token.token_address_by_name('DEF') == Address('0x0200000000000000000000000000000000000000') assert ERC20Token.token_address_by_name('GHI') == Address('0x0300000000000000000000000000000000000000') with pytest.raises(Exception): ERC20Token.token_address_by_name('XXX')
def __init__(self, chain: str): with open('keepers/config.json') as data_file: self.chain = chain self.config = json.load(data_file) for key, value in self.config[self.chain]["tokens"].items(): ERC20Token.register_token(Address(value), key)
logging_format = '%(asctime)-15s %(levelname)-8s %(name)-6s %(message)s' logging.basicConfig(format=logging_format, level=logging.INFO) # web3 = Web3(HTTPProvider(endpoint_uri=f"http://localhost:9545")) #mainnet web3 = Web3(HTTPProvider(endpoint_uri=f"http://localhost:8545")) #kovan web3.eth.defaultAccount = '0x002ca7F9b416B2304cDd20c26882d1EF5c53F611' our_address = Address(web3.eth.defaultAccount) # etherdelta_address = Address('0x8d12A197cB00D4747a1fe03395095ce2A5CC6819') #mainnet etherdelta_address = Address( '0xF4Ff487adA7bb29603077216082DA7f4bA989854') #kovan etherdelta = EtherDelta(web3, etherdelta_address) sai = ERC20Token(web3=web3, address=Address('0xb3e5b1e7fa92f827bdb79063df9173fefd07689d')) gem = ERC20Token(web3=web3, address=Address('0x53eccc9246c1e537d79199d0c7231e425a40f896')) etherdelta.approve([sai, gem], directly()) # print(len(etherdelta.active_onchain_orders())) # exit(-1) # # etherdelta.deposit_token(sai.address, Wad.from_number(0.5)) # etherdelta.withdraw_token(sai.address, Wad.from_number(0.4)) # logging.info(etherdelta.balance_of_token(sai.address, our_address)) # etherdelta.deposit(Wad.from_number(0.1)) # etherdelta.withdraw(Wad.from_number(0.01)) # logging.info(etherdelta.balance_of(our_address))
def register_tokens(token1, token2): ERC20Token.register_token(token1, 'TK1') ERC20Token.register_token(token2, 'TK2')