Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into sparrowDom/balancer…
Browse files Browse the repository at this point in the history
…-composable-st-pool
  • Loading branch information
sparrowDom committed Nov 29, 2023
2 parents a6f3285 + 3f8c91c commit c25642a
Show file tree
Hide file tree
Showing 141 changed files with 8,027 additions and 4,736 deletions.
25 changes: 25 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

RED='\033[0;31m'
NC='\033[0m'
GREEN='\033[0;32m'
files=""
# find all file ending with test.js that are not in node_modules
for file in $(find . -type d -name node_modules -prune -o -name '*test.js' -print); do
# uncomment below to debug which files match
# echo "$file"
# search if any contain it.only or describe.only
match=$(grep -E "(describe|it)\.only[[:space:]]*\(" "$file")

# add together the files containing .only
if [[ -n "${match}" ]]; then
files=${files}${file}'\n'
fi
done
if [[ -n "${files}" ]]; then
# fail pre-commit if
echo "${RED}Git pre-commit hook failed! Remove \".only\" from the following test file(s):${GREEN}"
echo ${files}
echo "${NC}"
exit 1
fi
61 changes: 20 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Origin Dollar
# Origin DeFi's OTokens: Origin Dollar (OUSD) and Origin Ether (OETH)

For more details about the product, checkout [our docs](https://docs.oeth.com).

OUSD is a new kind of stablecoin that passively accrues yield while you are holding it.
Checkout our [docs](https://docs.ousd.com) for more details about the product.
---

| Branch | CI/CD Status |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -156,44 +157,6 @@ Go to root of the project and run `npx husky install`

---

## (Core Contributors) Running dapp in Production/Staging Mode Locally

There may be a time that you will need to run the dapp in production/staging mode to test out a certain feature or do verification before a deploy. In this case there is no need for a local node as you will connect directly to the mainnet/testnet.

### Requirements

- `Google Cloud` CLI tool installed as explained [HERE](https://cloud.google.com/sdk/docs/quickstart)
- Permission to the Origin GCP Account to decrypt `*.secrets.enc` and deploy infrastructure

#### Login to Google Cloud

```
# Login to GCP
gcloud auth login
```

#### Staging

```
# Decrypt staging secrets to local
yarn run decrypt-secrets:staging
# Start local dapp in Staging mode
yarn run start:staging
```

#### Production

```
# Decrypt staging secrets to local
yarn run decrypt-secrets:production
# Start local dapp in Production mode
yarn run start:production
```

---

## Running Smoke Tests

Smoke tests can be run in 2 modes:
Expand Down Expand Up @@ -221,3 +184,19 @@ Want to contribute to OUSD? Awesome!
OUSD is an Open Source project and we welcome contributions of all sorts. There are many ways to help, from reporting issues, contributing to the code, and helping us improve our community.

The best way to get involved is to join the Origin Protocol [discord server](https://discord.gg/jyxpUSe) and head over to the channel named ORIGIN DOLLAR & DEFI

# Utils

## Git pre-commit hooks (using Husky)

### Setup
```
# install Husky
npx install husky
# from project root folder install Husky hooks
npx husky install
```

If the script in .husky/pre-commit returns non 0 exit the pre-commit hook will fail. Currently the script prevents a commit if there is an ".only" in the test scripts. Use "git commit --no-verify" if you have the hook enabled and you'd like to skip pre-commit check.
1 change: 1 addition & 0 deletions brownie/brownie-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotenv: .env
40 changes: 15 additions & 25 deletions brownie/collateralSwap.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,18 @@ def get_1inch_swap(
UNISWAP_SELECTOR = "0xf78dc253" #unoswapTo(address,address,uint256,uint256,uint256[])
UNISWAPV3_SWAP_TO_SELECTOR = "0xbc80f1a8" #uniswapV3SwapTo(address,uint256,uint256,uint256[])

result = get_1inch_swap_data(
from_token=from_token.lower(),
to_token=to_token.lower(),
swap_amount=from_amount,
slippage=slippage,
from_address=swapper_address.lower(),
to_address=vault_addr.lower(),
)

req = requests.get('https://{}.1inch.io/v5.0/1/swap'.format(ONEINCH_SUBDOMAIN), params={
'fromTokenAddress': from_token.lower(),
'fromAddress': swapper_address.lower(),
'destReceiver': vault_addr.lower(),
'toTokenAddress': to_token.lower(),
'amount': str(from_amount),
'allowPartialFill': allowPartialFill,
'disableEstimate': 'true',
'slippage': slippage
}, headers={
'accept': 'application/json'
})

if req.status_code != 200:
print(req.json())
raise Exception("Error calling 1inch api")

result = req.json()

input_decoded = router_1inch.decode_input(result['tx']['data'])
input_decoded = router_1inch.decode_input(result.input)

selector = result['tx']['data'][:10]
selector = result.input[:10]
data = '0x'
# Swap selector
if selector == SWAP_SELECTOR:
Expand All @@ -72,9 +61,9 @@ def get_1inch_swap(
raise Exception("Unrecognized 1Inch swap selector {}".format(selector))

swap_collateral_data = c_vault_core.swapCollateral.encode_input(
result['fromToken']['address'],
result['toToken']['address'],
result['fromTokenAmount'],
from_token.lower(),
to_token.lower(),
str(from_amount),
min_expected_amount,
data
)
Expand Down Expand Up @@ -130,6 +119,7 @@ def build_swap_tx(from_token, to_token, from_amount, max_slippage, allow_partial
if COINMARKETCAP_API_KEY is None:
raise Exception("Set coinmarketcap api key by setting CMC_API_KEY variable. Free plan key will suffice: https://coinmarketcap.com/api/pricing/")

c_vault_core = vault_core if from_token in OUSD_ASSET_ADDRESSES else oeth_vault_core
min_slippage_amount = scale_amount(WETH, from_token, 10**18) # 1 token of from_token (like 1WETH, 1DAI or 1USDT)
quote_1inch = get_1inch_quote(from_token, to_token, from_amount)
quote_1inch_min_swap_amount_price = get_1inch_quote(from_token, to_token, min_slippage_amount)
Expand Down Expand Up @@ -186,7 +176,7 @@ def build_swap_tx(from_token, to_token, from_amount, max_slippage, allow_partial
return to, data

decoded_input = vault_core.swapCollateral.decode_input(data)
return vault_core.swapCollateral(*decoded_input, {'from':STRATEGIST})
return c_vault_core.swapCollateral(*decoded_input, {'from':STRATEGIST})


# from_token, to_token, from_token_amount, slippage, allow_partial_fill, dry_run
Expand Down
63 changes: 38 additions & 25 deletions brownie/oneinch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,57 @@
import requests
from types import SimpleNamespace
import os
import json
import time

ONEINCH_API_KEY = os.getenv('ONEINCH_API_KEY')

def get_1inch_quote(from_token, to_token, from_amount, retry_on_ratelimit=True):
if len(ONEINCH_API_KEY) <= 0:
raise Exception("Missing API key")
res = requests.get('https://api.1inch.dev/swap/v5.2/1/quote', params={
'src': from_token,
'dst': to_token,
'amount': str(from_amount)
}, headers={
'accept': 'application/json',
'Authorization': 'Bearer {}'.format(ONEINCH_API_KEY)
})

ONEINCH_SUBDOMAIN = os.getenv('ONEINCH_SUBDOMAIN')
ONEINCH_SUBDOMAIN = ONEINCH_SUBDOMAIN if len(ONEINCH_SUBDOMAIN) > 0 else 'api'
if retry_on_ratelimit and res.status_code == 429:
time.sleep(2) # Wait for 2s and then try again
return get_1inch_quote(from_token, to_token, from_amount, False)
elif res.status_code != 200:
raise Exception("Error accessing 1inch api")

def get_1inch_quote(from_token, to_token, from_amount):
req = requests.get('https://{}.1inch.io/v5.0/1/quote'.format(ONEINCH_SUBDOMAIN), params={
'fromTokenAddress': from_token,
'toTokenAddress': to_token,
'amount': str(from_amount)
}, headers={
'accept': 'application/json'
})
result = json.loads(res.text)

if req.status_code != 200:
print(req.json())
raise Exception("Error accessing 1inch api")
return int(result['toAmount'])

result = req.json()
return int(result['toTokenAmount'])
def get_1inch_swap_data(from_token, to_token, swap_amount, slippage, from_address=STRATEGIST, to_address=STRATEGIST, retry_on_ratelimit=True):
if len(ONEINCH_API_KEY) <= 0:
raise Exception("Missing API key")

def get_1inch_swap_data(from_token, to_token, swap_amount, slippage, from_address=STRATEGIST, to_address=STRATEGIST):
req = requests.get('https://{}.1inch.io/v5.0/1/swap'.format(ONEINCH_SUBDOMAIN), params={
'fromTokenAddress': from_token,
res = requests.get('https://api.1inch.dev/swap/v5.2/1/swap', params={
'src': from_token,
'fromAddress': from_address,
'destReceiver': to_address,
'toTokenAddress': to_token,
'receiver': to_address,
'dst': to_token,
'amount': str(swap_amount),
'allowPartialFill': True,
'disableEstimate': 'true',
'slippage': slippage
}, headers={
'accept': 'application/json'
'accept': 'application/json',
'Authorization': 'Bearer {}'.format(ONEINCH_API_KEY)
})

if req.status_code != 200:
print(req.json())
raise Exception("Error calling 1inch api")
if retry_on_ratelimit and res.status_code == 429:
time.sleep(2) # Wait for 2s and then try again
return get_1inch_swap_data(from_token, to_token, swap_amount, slippage, from_address, to_address, False)
elif res.status_code != 200:
raise Exception("Error accessing 1inch api")

result = req.json()
result = json.loads(res.text)

return SimpleNamespace(receiver = result['tx']['to'], input = result['tx']['data'])
2 changes: 1 addition & 1 deletion brownie/prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_cmc_quote(from_token, to_token, from_amount):

if req.status_code != 200:
print(req.json())
raise Exception("Error accessing 1inch api")
raise Exception("Error accessing CMC api")

result = req.json()

Expand Down
Loading

0 comments on commit c25642a

Please sign in to comment.