Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
martyn committed Oct 31, 2024
1 parent bfcefac commit 0eedcb0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
4 changes: 4 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ COPY . .
# Build the app
RUN npm run build

# Generate Prisma client
RUN npx prisma generate

# Prune non-production dependencies
RUN npm prune --production

Expand All @@ -29,6 +32,7 @@ COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/package.json ./
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma

# Add the migration and start command
CMD ["sh", "-c", "npm run migrate && npm start"]
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@web3modal/wagmi": "^5.1.10",
"bootstrap": "^5",
"bootstrap-icons": "^1.11.3",
"decimal": "^0.0.2",
"decimal.js": "^10.4.3",
"near-api-js": "^4.0.3",
"next": "14.2.13",
"prisma": "^5.20.0",
Expand Down
2 changes: 0 additions & 2 deletions app/src/app/prediction-markets/[poolId]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ export default function PoolDetails() {
}

const handleRunAI = async () => {
const newLog = { action: 'AI run', time: new Date().toLocaleTimeString() };
setActions((prevLogs) => [newLog, ...prevLogs]);
alert('AI has been triggered!');
await queueJob("runAI", {});
};
Expand Down
6 changes: 3 additions & 3 deletions app/src/pages/api/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export default async function handler(req, res) {
if(!pool.holdings.USDC) {
pool.holdings.USDC = {name: "USDC", amount:"0"};
}
if(!pool.holdings[POLY_QUESTION]) {
pool.holdings[POLY_QUESTION] = {name: POLY_QUESTION, amount:"100", cost_basis: "0.1"};
}
//if(!pool.holdings[POLY_QUESTION]) {
// pool.holdings[POLY_QUESTION] = {name: POLY_QUESTION, amount:"100", cost_basis: "0.1"};
//}
pool.holdings.NEAR = {name: "NEAR", amount: await getNearBalance(name)};

const parsedEvents = await fetchAndParseEvents(POLY_EVENT);
Expand Down
21 changes: 8 additions & 13 deletions oracle/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from decimal import Decimal, ROUND_DOWN

# Set up PoolApiClient with the AILP URL
AILP_URL = os.getenv('AILPURL', 'http://localhost:3000')
SMARTPOOL_URL = os.getenv('SMARTPOOL_URL', 'http://localhost:3000')
NEAR_CONFIG=os.getenv("NEAR_CONFIG", "")
NEARAI_CALLBACK_URL=os.getenv("NEARAI_CALLBACK_URL", "")
pool_api = PoolApiClient(AILP_URL)
pool_api = PoolApiClient(SMARTPOOL_URL)

def fetch_jobs():
"""Fetches pending jobs from the Pool API."""
Expand Down Expand Up @@ -63,14 +63,14 @@ def call_near_ai_api(pool_name, prediction_market_url, usdc_available, holdings)
}

payload = json.dumps({
"agent_id": "smartpool.near/prediction-market-assistant/0.0.14",
"new_message": new_message,
"agent_id": "smartpool.near/prediction-market-assistant/0.1.0",
"new_message": json.dumps(new_message),
"max_iterations": 1
}).encode("utf-8")

req = urllib.request.Request(url, data=payload, headers=headers)
try:
print("Calling...")
print("Calling...", url, payload, headers)
with urllib.request.urlopen(req) as response:
result = response.read()
print("RESULT")
Expand All @@ -80,12 +80,12 @@ def call_near_ai_api(pool_name, prediction_market_url, usdc_available, holdings)
print(f"Error calling NEAR AI API: {e}")
return None

def runAI(pool):
def runAI(pool, pool_name):
# TODO needs current prices
print("--", pool)
holdings = pool["holdings"]
usdc = pool["holdings"]["USDC"]["amount"]
response = call_near_ai_api(pool.name, "https://polymarket.com/event/when-will-gpt-5-be-announced?tid=1729566306341", usdc, holdings)
response = call_near_ai_api(pool_name, "https://polymarket.com/event/when-will-gpt-5-be-announced?tid=1729566306341", usdc, holdings)
print("___", response)
return {"operation": "BUY"}, "http://fake url"

Expand Down Expand Up @@ -124,7 +124,7 @@ async def process_job(job):

elif action == 'runAI':
pool = pool_api.get_pool(pool_name)
ai_action, log_url = runAI(pool)
ai_action, log_url = runAI(pool, pool_name)
pool_api.record_action(
pool_name,
"AI CALL",
Expand All @@ -135,11 +135,6 @@ async def process_job(job):
}
)

if ai_action["operation"] == "BUY":
print("Should BUY here", ai_action)
elif ai_action["operation"] == "SELL":
print("Should SELL here", ai_action)

print(f"NEAR AI run executed")

elif action == 'fulfillDeposit':
Expand Down

0 comments on commit 0eedcb0

Please sign in to comment.