def __init__(self, tub: Tub): self.tub = tub super().__init__(source_token=self.tub.skr(), target_token=self.tub.gem(), rate=tub.jar_bid(), max_source_amount=Wad.from_number(1000000), #1 mio SKR = infinity ;) method="tub.exit()")
def __init__(self, tub: Tub): self.tub = tub super().__init__(source_token=self.tub.gem(), target_token=self.tub.skr(), rate=(Ray.from_number(1) / tub.jar_ask()), max_source_amount=Wad.from_number(1000000), #1 mio ETH = infinity ;) method="tub.join()")
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')
def new_sai() -> SaiDeployment: def deploy(web3, contract_name, args=None): contract_factory = web3.eth.contract( abi=json.loads( pkg_resources.resource_string('api.feed', f'abi/{contract_name}.abi')), bytecode=pkg_resources.resource_string('api.feed', f'abi/{contract_name}.bin')) tx_hash = contract_factory.deploy(args=args) receipt = web3.eth.getTransactionReceipt(tx_hash) return receipt['contractAddress'] web3 = Web3(EthereumTesterProvider()) web3.eth.defaultAccount = web3.eth.accounts[0] our_address = Address(web3.eth.defaultAccount) sai = DSToken.deploy(web3, 'SAI') sin = DSToken.deploy(web3, 'SIN') gem = DSToken.deploy(web3, 'ETH') pip = DSValue.deploy(web3) skr = DSToken.deploy(web3, 'SKR') pot = DSVault.deploy(web3) pit = DSVault.deploy(web3) tip = deploy(web3, 'Tip') dad = DSGuard.deploy(web3) jug = deploy(web3, 'SaiJug', [sai.address.address, sin.address.address]) jar = deploy( web3, 'SaiJar', [skr.address.address, gem.address.address, pip.address.address]) tub = Tub.deploy(web3, Address(jar), Address(jug), pot.address, pit.address, Address(tip)) tap = Tap.deploy(web3, tub.address, pit.address) top = Top.deploy(web3, tub.address, tap.address) # set permissions dad.permit(DSGuard.ANY, DSGuard.ANY, DSGuard.ANY) for auth in [sai, sin, skr, pot, pit, tub, tap, top]: auth.set_authority(dad.address) # approve, mint some GEMs tub.approve(directly()) gem.mint(Wad.from_number(1000000)) web3.currentProvider.rpc_methods.evm_snapshot() return SaiDeployment(web3, our_address, gem, sai, skr, tub, tap, top)
class SaiKeeper(Keeper): 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') def startup(self): # implemented only to avoid IntelliJ IDEA warning super().startup()
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.")
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # 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"------------------")
# 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 Wad from api.sai import Tub, Lpc web3 = Web3(HTTPProvider(endpoint_uri=f"http://localhost:8545")) web3.eth.defaultAccount = "0x002ca7F9b416B2304cDd20c26882d1EF5c53F611" our_address = Address(web3.eth.defaultAccount) tub = Tub(web3=web3, address=Address('0xc349a197c9c3200411094adec82972a2b921c6e2')) lpc = Lpc(web3=web3, address=Address('0x421943ce89b6d0daf0128aafc679079050aa0c1e')) sai = ERC20Token(web3=web3, address=tub.sai()) gem = ERC20Token(web3=web3, address=tub.gem()) # Print our SAI and GEM (W-ETH) balance print(f"Our balance before the exchange is: {sai.balance_of(our_address)} SAI") print(f" {gem.balance_of(our_address)} W-ETH") print(f"") print(f"Attempting to get 10 SAI in exchange for W-ETH...") print(f"") # Perform the exchange (`take()`) via LPC # Print our balances again afterwards if lpc.take(tub.sai(), Wad.from_number(10)): print(f"Exchange was successful.")