Skip to content

Commit

Permalink
Add tilt and docker + address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
m30m committed Oct 10, 2024
1 parent c7f3fb9 commit 9365be0
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 27 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/push-rust-services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,28 @@ jobs:
push: true
tags: ${{ steps.meta_swap_beacon.outputs.tags }}
labels: ${{ steps.meta_swap_beacon.outputs.labels }}
limonade:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta_limonade
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-limonade
tags: |
type=sha,event=branch
type=ref,event=tag
- name: Build and push swap beacon docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: ./scripts/limonade
push: true
tags: ${{ steps.meta_limonade.outputs.tags }}
labels: ${{ steps.meta_limonade.outputs.labels }}
6 changes: 6 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,9 @@ local_resource(
"poetry -C per_sdk run python3 -m per_sdk.svm.dummy_tx -v --file-private-key-searcher keypairs/searcher.json --file-private-key-relayer-signer keypairs/relayer_signer.json --bid 100000000 --auction-server-url http://localhost:9000 --express-relay-program PytERJFhAKuNNuaiXkApLfWzwNwSNDACpigT3LwQfou --dummy-program DUmmYXYFZugRn2DS4REc5F9UbQNoxYsHP1VMZ6j5U7kZ",
resource_deps=["svm-initialize-programs", "auction-server"],
)

local_resource(
"svm-limonade",
serve_cmd="npm run --prefix scripts/limonade limonade -- --global-config $(solana-keygen pubkey keypairs/limo_global_config.json) --endpoint http://127.0.0.1:9000 --chain-id development-solana --api-key $(poetry -C per_sdk run python3 create_limo_profile.py) --rpc-endpoint %s" % rpc_url_solana,
resource_deps=["svm-initialize-programs", "auction-server"],
)
21 changes: 21 additions & 0 deletions create_limo_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
This script is used to generate a new api key for the limo profile for the limonade service.
"""

import requests
import random

def main():
headers = {'Authorization':'Bearer admin'}
random_id = random.randint(0, 10000000)
response = requests.post('http://localhost:9000/v1/profiles', json={'name': 'limo', 'email':f'limo{random_id}@dourolabs.com','role':'protocol'}, headers=headers)
profile_id = response.json()['id']

response = requests.post('http://localhost:9000/v1/profiles/access_tokens', json={'profile_id':profile_id}, headers=headers)
access_token = response.json()['token']
print(access_token)



if __name__ == '__main__':
main()
65 changes: 65 additions & 0 deletions scripts/limonade/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# syntax=docker/dockerfile:1

# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/go/dockerfile-reference/

# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7

ARG NODE_VERSION=18.20.2

################################################################################
# Use node image for base image for all stages.
FROM node:${NODE_VERSION}-alpine as base

# Set working directory for all build stages.
WORKDIR /usr/src/app


################################################################################
# Create a stage for installing production dependecies.
FROM base as deps

# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.npm to speed up subsequent builds.
# Leverage bind mounts to package.json and package-lock.json to avoid having to copy them
# into this layer.
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=package-lock.json,target=package-lock.json \
--mount=type=cache,target=/root/.npm \
npm ci --omit=dev

################################################################################
# Create a stage for building the application.
FROM deps as build

# Download additional development dependencies before building, as some projects require
# "devDependencies" to be installed to build. If you don't need this, remove this step.
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=package-lock.json,target=package-lock.json \
--mount=type=cache,target=/root/.npm \
npm ci

# Copy the rest of the source files into the image.
COPY . .
# Run the build script.
RUN npm run build

################################################################################
# Create a new stage to run the application with minimal runtime dependencies
# where the necessary files are copied from the build stage.
FROM base as final

# Use production node environment by default.
ENV NODE_ENV production

# Run the application as a non-root user.
USER node

# Copy package.json so that package manager commands can be used.
COPY package.json .

# Copy the production dependencies from the deps stage and also
# the built application from the build stage into the image.
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=build /usr/src/app/dist ./dist
2 changes: 1 addition & 1 deletion scripts/limonade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This script is used to submit new opportunities fetched from the limo program to
How to run:

```bash
npm run opportunity-updater -- \
npm run limonade -- \
--global-config TeStcUQMmECYEtdeXo9cXpktQWaGe4bhJ7zxAUMzB2X \
--endpoint https://per-staging.dourolabs.app/ \
--chain-id development-solana \
Expand Down
4 changes: 2 additions & 2 deletions scripts/limonade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1",
"opportunity-updater": "npm run build && node dist/index.js"
"limonade": "npm run build && node dist/index.js"
},
"keywords": [],
"author": "",
Expand All @@ -20,7 +20,7 @@
"@coral-xyz/anchor": "^0.30.1",
"@coral-xyz/anchor-cli": "^0.30.1",
"@kamino-finance/limo-sdk": "^0.2.1",
"@pythnetwork/express-relay-js": "/Users/amin/Projects/pyth-crosschain/express_relay/sdk/js",
"@pythnetwork/express-relay-js": "^0.11.0",
"@solana/web3.js": "^1.95.3",
"axios": "^1.7.3",
"bs58": "^6.0.0",
Expand Down
51 changes: 27 additions & 24 deletions scripts/limonade/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,33 @@ async function run() {
let { blockhash: latestBlockhash } = await connection.getLatestBlockhash(
"confirmed"
);
const response = await connection.getProgramAccounts(limoId, {
commitment: "confirmed",
filters,
withContext: true,
});
const payloads = [];
for (const account of response.value) {
const order = Order.decode(account.account.data);
if (order.remainingInputAmount.toNumber() === 0) {
continue;
const submitExistingOpportunities = async () => {
const response = await connection.getProgramAccounts(limoId, {
commitment: "confirmed",
filters,
withContext: true,
});
const payloads: OpportunityCreate[] = response.value
.map((account) => ({
program: "limo" as const,
blockHash: latestBlockhash,
chainId: argv.chainId,
slot: response.context.slot,
order: {
state: Order.decode(account.account.data),
address: account.pubkey,
},
}))
.filter(
(opportunityCreate) =>
opportunityCreate.order.state.remainingInputAmount.toNumber() !== 0
);

console.log("Initial opportunities", payloads.length);
for (const payload of payloads) {
await client.submitOpportunity(payload);
}
const payload: OpportunityCreate = {
program: "limo",
blockHash: latestBlockhash,
chainId: argv.chainId,
slot: response.context.slot,
order: { state: order, address: account.pubkey },
};
payloads.push(payload);
}
console.log("Initial opportunities", payloads.length);
for (const payload of payloads) {
await client.submitOpportunity(payload);
}
};

connection.onProgramAccountChange(
limoId,
Expand Down Expand Up @@ -121,7 +124,7 @@ async function run() {
await new Promise((resolve) => setTimeout(resolve, 10000));
}
};
await updateLatestBlockhash();
await Promise.all([updateLatestBlockhash(), submitExistingOpportunities()]);
}

run();

0 comments on commit 9365be0

Please sign in to comment.