2020# 2 = 2%
2121MAX_PRICE_DEVIATION = 2
2222
23- OUSD_ASSET_ADDRESSES = (DAI , USDT , USDC )
23+ OUSD_ASSET_ADDRESSES = (USDS , USDT , USDC )
2424
2525def get_1inch_swap (
2626 from_token ,
@@ -29,9 +29,11 @@ def get_1inch_swap(
2929 slippage ,
3030 allowPartialFill ,
3131 min_expected_amount ,
32+ protocols = "" ,
3233):
3334 vault_addr = VAULT_PROXY_ADDRESS if from_token in OUSD_ASSET_ADDRESSES else VAULT_OETH_PROXY_ADDRESS
3435 c_vault_core = vault_core if from_token in OUSD_ASSET_ADDRESSES else oeth_vault_core
36+ c_vault_admin = vault_admin if from_token in OUSD_ASSET_ADDRESSES else vault_oeth_admin
3537
3638 router_1inch = load_contract ('router_1inch_v5' , ROUTER_1INCH_V5 )
3739 SWAP_SELECTOR = "0x12aa3caf" #swap(address,(address,address,address,address,uint256,uint256,uint256),bytes,bytes)
@@ -45,6 +47,7 @@ def get_1inch_swap(
4547 slippage = slippage ,
4648 from_address = swapper_address .lower (),
4749 to_address = vault_addr .lower (),
50+ protocols = protocols ,
4851 )
4952
5053 input_decoded = router_1inch .decode_input (result .input )
@@ -60,7 +63,7 @@ def get_1inch_swap(
6063 else :
6164 raise Exception ("Unrecognized 1Inch swap selector {}" .format (selector ))
6265
63- swap_collateral_data = c_vault_core .swapCollateral .encode_input (
66+ swap_collateral_data = c_vault_admin .swapCollateral .encode_input (
6467 from_token .lower (),
6568 to_token .lower (),
6669 "%.0f" % from_amount ,
@@ -115,39 +118,40 @@ def get_oracle_router_quote(from_token, to_token, from_amount):
115118# 2 = 2%
116119# - partial_fill -> are partial fills allowed
117120# - dry_run -> If set to True, doesn't run the tx against the active network
118- def build_swap_tx (from_token , to_token , from_amount , max_slippage , allow_partial_fill , dry_run = True ):
121+ def build_swap_tx (from_token , to_token , from_amount , max_slippage , allow_partial_fill , dry_run = True , protocols = "" ):
119122 if COINMARKETCAP_API_KEY is None :
120123 raise Exception ("Set coinmarketcap api key by setting CMC_API_KEY variable. Free plan key will suffice: https://coinmarketcap.com/api/pricing/" )
121124
122125 c_vault_core = vault_core if from_token in OUSD_ASSET_ADDRESSES else oeth_vault_core
126+ c_vault_admin = vault_admin if from_token in OUSD_ASSET_ADDRESSES else vault_oeth_admin
123127 min_slippage_amount = scale_amount (WETH , from_token , 10 ** 18 ) # 1 token of from_token (like 1WETH, 1DAI or 1USDT)
124- quote_1inch = get_1inch_quote (from_token , to_token , from_amount )
125- quote_1inch_min_swap_amount_price = get_1inch_quote (from_token , to_token , min_slippage_amount )
128+ quote_1inch = get_1inch_quote (from_token , to_token , from_amount , protocols = protocols )
129+ quote_1inch_min_swap_amount_price = get_1inch_quote (from_token , to_token , min_slippage_amount , protocols = protocols )
126130 quote_1inch_min_swap_amount = from_amount * quote_1inch_min_swap_amount_price / min_slippage_amount
127- quote_oracles = get_oracle_router_quote (from_token , to_token , from_amount )
128- quote_coingecko = get_coingecko_quote (from_token , to_token , from_amount )
129- quote_cmc = get_cmc_quote (from_token , to_token , from_amount )
131+ # quote_oracles = get_oracle_router_quote(from_token, to_token, from_amount)
132+ # quote_coingecko = get_coingecko_quote(from_token, to_token, from_amount)
133+ # quote_cmc = get_cmc_quote(from_token, to_token, from_amount)
130134
131135 # subtract the max slippage from minimum slippage query
132136 min_tokens_with_slippage = scale_amount (from_token , to_token , from_amount * quote_1inch_min_swap_amount_price * (100 - max_slippage ) / 100 / min_slippage_amount )
133- coingecko_to_1inch_diff = (quote_1inch - quote_coingecko ) / quote_1inch
134- oracle_to_1inch_diff = (quote_1inch - quote_oracles ) / quote_1inch
135- cmc_to_1inch_diff = (quote_1inch - quote_cmc ) / quote_1inch
137+ # coingecko_to_1inch_diff = (quote_1inch - quote_coingecko) / quote_1inch
138+ # oracle_to_1inch_diff = (quote_1inch - quote_oracles) / quote_1inch
139+ # cmc_to_1inch_diff = (quote_1inch - quote_cmc) / quote_1inch
136140
137141 actual_slippage = (quote_1inch_min_swap_amount - quote_1inch ) / quote_1inch
138142
139143 print ("------ Price Quotes ------" )
140144 print ("1Inch expected tokens: {:.6f}" .format (scale_amount (to_token , 'human' , quote_1inch )))
141145 print ("1Inch expected tokens (no slippage): {:.6f}" .format (scale_amount (to_token , 'human' , quote_1inch_min_swap_amount )))
142- print ("Oracle expected tokens: {:.6f}" .format (scale_amount (to_token , 'human' , quote_oracles )))
143- print ("Coingecko expected tokens: {:.6f}" .format (scale_amount (to_token , 'human' , quote_coingecko )))
144- print ("CoinmarketCap expected tokens: {:.6f}" .format (scale_amount (to_token , 'human' , quote_cmc )))
146+ # print("Oracle expected tokens: {:.6f}".format(scale_amount(to_token, 'human', quote_oracles)))
147+ # print("Coingecko expected tokens: {:.6f}".format(scale_amount(to_token, 'human', quote_coingecko)))
148+ # print("CoinmarketCap expected tokens: {:.6f}".format(scale_amount(to_token, 'human', quote_cmc)))
145149 print ("Tokens expected (with {:.2f}% slippage) {:.6f}" .format (max_slippage , scale_amount (to_token , 'human' , min_tokens_with_slippage )))
146- print ("" )
147- print ("------ Price Diffs -------" )
148- print ("1Inch to Oracle Difference: {:.6f}%" .format (oracle_to_1inch_diff * 100 ))
149- print ("1Inch to Coingecko Difference: {:.6f}%" .format (coingecko_to_1inch_diff * 100 ))
150- print ("1Inch to CoinmarketCap Difference: {:.6f}%" .format (cmc_to_1inch_diff * 100 ))
150+ # print("")
151+ # print("------ Price Diffs -------")
152+ # print("1Inch to Oracle Difference: {:.6f}%".format(oracle_to_1inch_diff * 100))
153+ # print("1Inch to Coingecko Difference: {:.6f}%".format(coingecko_to_1inch_diff * 100))
154+ # print("1Inch to CoinmarketCap Difference: {:.6f}%".format(cmc_to_1inch_diff * 100))
151155 print ("" )
152156 print ("-------- Slippage --------" )
153157 print ("Current market Slippage: {:.6f}%" .format (actual_slippage * 100 ))
@@ -160,23 +164,23 @@ def build_swap_tx(from_token, to_token, from_amount, max_slippage, allow_partial
160164 print (console_colors ["FAIL" ] + error + console_colors ["ENDC" ])
161165 raise Exception (error )
162166
163- for protocol , price_diff in {
164- "Oracle" : oracle_to_1inch_diff ,
165- "Coingecko" : coingecko_to_1inch_diff ,
166- "CoinmarketCap" : cmc_to_1inch_diff
167- }.items ():
168- if (abs (price_diff * 100 ) > MAX_PRICE_DEVIATION ):
169- error = "1Inch and {} have too large price deviation: {:.6f}%" .format (protocol , price_diff * 100 )
170- print (console_colors ["FAIL" ] + error + console_colors ["ENDC" ])
171- raise Exception (error )
167+ # for protocol, price_diff in {
168+ # "Oracle": oracle_to_1inch_diff,
169+ # "Coingecko": coingecko_to_1inch_diff,
170+ # "CoinmarketCap": cmc_to_1inch_diff
171+ # }.items():
172+ # if (abs(price_diff * 100) > MAX_PRICE_DEVIATION):
173+ # error = "1Inch and {} have too large price deviation: {:.6f}%".format(protocol, price_diff * 100)
174+ # print(console_colors["FAIL"] + error + console_colors["ENDC"])
175+ # raise Exception(error)
172176
173- to , data = get_1inch_swap (from_token , to_token , from_amount , max_slippage , allow_partial_fill , min_tokens_with_slippage )
177+ to , data = get_1inch_swap (from_token , to_token , from_amount , max_slippage , allow_partial_fill , min_tokens_with_slippage , protocols = "USDS_MIGRATOR,LITEPSM_USDC" )
174178
175179 if dry_run == True :
176180 return to , data
177181
178- decoded_input = vault_core .swapCollateral .decode_input (data )
179- return c_vault_core .swapCollateral (* decoded_input , {'from' :STRATEGIST })
182+ decoded_input = vault_admin .swapCollateral .decode_input (data )
183+ return c_vault_admin .swapCollateral (* decoded_input , {'from' :STRATEGIST })
180184
181185
182186# from_token, to_token, from_token_amount, slippage, allow_partial_fill, dry_run
0 commit comments