Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Dynamic cap tests #129

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions feeds/synthetic.json

Large diffs are not rendered by default.

93 changes: 93 additions & 0 deletions scripts/synthetic_feed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import json
import os
import brownie
from brownie import (
accounts,
chain,
interface
)

from datetime import datetime
import time

def main():

cur_tick = -80000
cum_tick = 0

delta = 15

now = int(time.time())

print(time.time())

feed = {
'description': 'A synthesized price feed for our UniswapV3 oracle mock.',
'observations': [],
'shims': [],

}
obs = []
shims = []

for i in range(1000):

now += delta

cum_tick += cur_tick * delta

ob = [now, cum_tick, 0, True]

shim = [now, 8870817966431808984, cur_tick, i]

obs.append(ob)
shims.append(shim)
feed['observations'].append(ob)
feed['shims'].append(shim)

cur_tick -= 1

print(feed)

factory = accounts[0].deploy(getattr(brownie, 'UniswapV3FactoryMock'))

print("deployed")

IUniswapV3OracleMock = getattr(interface, 'IUniswapV3OracleMock')

zeroth = "0x0000000000000000000000000000000000000000"

factory.createPool(zeroth, zeroth)

print("created")

mock = IUniswapV3OracleMock(factory.allPools(0))

print("got mock")

mock.loadObservations(obs, shims, {'from': accounts[0]})

print("loaded observation")

spots = []

now = int(time.time())
start = now + 15
for x in range(950):

chain.mine(timestamp=start + (x*delta))

ob = mock.observe([1, 0])

spot = 1.0001 ** (ob[0][1]-ob[0][0])

print("spot", spot)

spots.append(spot)

base = os.path.dirname(os.path.abspath(__file__))

path = os.path.join(base, '../feeds/synthetic.json')

with open(os.path.normpath(path), 'w+') as f:
json.dump(feed, f)