diff --git a/.github/workflows/deploy-server-og-evm.yml b/.github/workflows/deploy-server-og-evm.yml new file mode 100644 index 0000000..882104a --- /dev/null +++ b/.github/workflows/deploy-server-og-evm.yml @@ -0,0 +1,55 @@ +name: Deploy to AWS + +on: + workflow_dispatch: + +jobs: + build-and-deploy: + name: Build and Deploy + runs-on: ubuntu-latest + environment: production + + env: + ECS_CLUSTER: MemChat + ECS_SERVICE: memchat-facilitator-x402-og-evm + ECR_REPOSITORY: memchat/facilitator-x402-og-evm + IMAGE_TAG: latest + AWS_REGION: us-east-2 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Build, tag, and push image to Amazon ECR + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + echo "Docker image successfully pushed to ECR!" + + - name: Force new deployment on Amazon ECS + run: | + aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --force-new-deployment > /dev/null + echo "New ECS deployment started!" + + - name: AWS LINKS TO VIEW DEPLOYMENT + run: | + echo "View deployment progress here - https://us-east-2.console.aws.amazon.com/ecs/v2/clusters/MemChat/services/facilitator-x402-og-evm/tasks?region=us-east-2" + + - name: Wait for ECS service to stabilize + run: | + echo "Waiting for ECS service to stabilize..." + aws ecs wait services-stable --cluster $ECS_CLUSTER --services $ECS_SERVICE + echo "✅ ECS service is now stable and deployment is complete!" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3109ac0..4adc41e 100644 --- a/.gitignore +++ b/.gitignore @@ -141,4 +141,6 @@ vite.config.ts.timestamp-* .vite/ # walrus config -walrus_config \ No newline at end of file +walrus_config + +.DS_Store \ No newline at end of file diff --git a/index.ts b/index.ts index 6d2b921..a54c984 100644 --- a/index.ts +++ b/index.ts @@ -113,7 +113,7 @@ app.get("/supported", async (req: Request, res: Response) => { kinds.push({ x402Version: 1, scheme: "exact", - network: "og-devnet", + network: "og-evm", }); } @@ -145,6 +145,7 @@ app.post("/settle", async (req: Request, res: Response) => { const inputHash = headers["x-input-hash"] as string; const outputHash = headers["x-output-hash"] as string; const settlementType = headers["x-settlement-type"] as string; + const modelType = headers["x-model-type"] as string; const paymentRequirements = PaymentRequirementsSchema.parse(body.paymentRequirements); const paymentPayload = PaymentPayloadSchema.parse(body.paymentPayload); @@ -162,12 +163,13 @@ app.post("/settle", async (req: Request, res: Response) => { // settle payment const response = await settle(signer, paymentPayload, paymentRequirements, x402Config); // settle input and output - const settlement_data = { + const settlement_data = { network: paymentRequirements.network, inputHash, outputHash, msg: "", settlement_type: settlementType, + model_type: modelType, } const payload_resp = await settlePayload(signer, settlement_data, x402Config); diff --git a/typescript/packages/x402/src/facilitator/facilitator.ts b/typescript/packages/x402/src/facilitator/facilitator.ts index 8f73113..1e64aea 100644 --- a/typescript/packages/x402/src/facilitator/facilitator.ts +++ b/typescript/packages/x402/src/facilitator/facilitator.ts @@ -180,6 +180,7 @@ export async function settlePayload( outputHash: string; msg: string; settlement_type: string; + model_type?: string; }, config?: X402Config ): Promise<{ success: boolean; transaction?: string; error?: string }> { @@ -194,6 +195,7 @@ export async function settlePayload( data.outputHash, data.msg, data.settlement_type, + data.model_type, ); console.log("Enqueued payload settlement job:", jobId); diff --git a/typescript/packages/x402/src/facilitator/queue.ts b/typescript/packages/x402/src/facilitator/queue.ts index f655f51..5dc8df5 100644 --- a/typescript/packages/x402/src/facilitator/queue.ts +++ b/typescript/packages/x402/src/facilitator/queue.ts @@ -21,6 +21,7 @@ export interface SettlePayloadJob extends BaseJob { network: string; inputHash: string; outputHash: string; + modelType?: string; msg: string; settlement_type: string; } @@ -82,6 +83,7 @@ export class PaymentQueue { outputHash: string, msg: string, settlement_type: string, + model_type?: string, ): Promise { const id = Math.random().toString(36).substring(7); const job: SettlePayloadJob = { @@ -92,6 +94,7 @@ export class PaymentQueue { outputHash, msg, settlement_type, + modelType: model_type, timestamp: Date.now(), }; diff --git a/typescript/packages/x402/src/facilitator/worker.ts b/typescript/packages/x402/src/facilitator/worker.ts index 0aed05e..d503944 100644 --- a/typescript/packages/x402/src/facilitator/worker.ts +++ b/typescript/packages/x402/src/facilitator/worker.ts @@ -90,6 +90,7 @@ export async function startWorker( network: job.network, inputHash: job.inputHash, outputHash: job.outputHash, + modelType: job.modelType, msg: job.msg, settlement_type: job.settlement_type, }); @@ -187,7 +188,7 @@ async function flushBuffer( } async function uploadToWalrus(data: string): Promise { - const PUBLISHER_URL = process.env.WALRUS_PUBLISHER_URL || "http://localhost:9002/v1/blobs"; + const PUBLISHER_URL = process.env.WALRUS_PUBLISHER_URL || "https://ogpublisher.opengradient.ai/v1/blobs"; const url = `${PUBLISHER_URL}?epochs=10`; console.log(`Uploading batch to Walrus Mainnet: ${PUBLISHER_URL}`); diff --git a/typescript/packages/x402/src/types/shared/evm/config.ts b/typescript/packages/x402/src/types/shared/evm/config.ts index fd77385..d5c99e9 100644 --- a/typescript/packages/x402/src/types/shared/evm/config.ts +++ b/typescript/packages/x402/src/types/shared/evm/config.ts @@ -64,8 +64,8 @@ export const config: Record = { usdcAddress: "0xF1815bd50389c46847f0Bda824eC8da914045D14", usdcName: "Bridged USDC", }, - "10744": { - usdcAddress: "0x48515A4b24f17cadcD6109a9D85a57ba55a619a6", + "10740": { + usdcAddress: "0x094E464A23B90A71a0894D5D1e5D470FfDD074e1", usdcName: "OUSDC", }, }; diff --git a/typescript/packages/x402/src/types/shared/evm/wallet.ts b/typescript/packages/x402/src/types/shared/evm/wallet.ts index 10b61cc..30e3d7c 100644 --- a/typescript/packages/x402/src/types/shared/evm/wallet.ts +++ b/typescript/packages/x402/src/types/shared/evm/wallet.ts @@ -229,29 +229,29 @@ export function getChainFromNetwork(network: string | undefined): Chain { return iotex; case "iotex-testnet": return iotexTestnet; - case "og-devnet": - return ogDevnet; + case "og-evm": + return ogEvm; default: throw new Error(`Unsupported network: ${network}`); } } -export const ogDevnet = /*#__PURE__*/ defineChain({ - id: 10744, - name: 'OG Devnet', +export const ogEvm = /*#__PURE__*/ defineChain({ + id: 10740, + name: 'OG EVM', nativeCurrency: { decimals: 18, name: 'OG', symbol: 'OG', }, rpcUrls: { - default: { http: ['https://eth-devnet.opengradient.ai/'] }, + default: { http: ['https://ogevmdevnet.opengradient.ai/'] }, }, blockExplorers: { default: { - name: 'OG Explorer', - url: 'https://explorer.og.artela.io', + name: 'OG EVM Explorer', + url: 'https://explorer.og.artela.io', // TODO: update }, }, contracts: { diff --git a/typescript/packages/x402/src/types/shared/network.ts b/typescript/packages/x402/src/types/shared/network.ts index 91975da..8c92525 100644 --- a/typescript/packages/x402/src/types/shared/network.ts +++ b/typescript/packages/x402/src/types/shared/network.ts @@ -16,7 +16,7 @@ export const NetworkSchema = z.enum([ "polygon-amoy", "peaq", "story", - "og-devnet", + "og-evm", ]); export type Network = z.infer; @@ -35,7 +35,7 @@ export const SupportedEVMNetworks: Network[] = [ "polygon-amoy", "peaq", "story", - "og-devnet", + "og-evm", ]; export const EvmNetworkToChainId = new Map([ ["abstract", 2741], @@ -51,7 +51,7 @@ export const EvmNetworkToChainId = new Map([ ["polygon-amoy", 80002], ["peaq", 3338], ["story", 1514], - ["og-devnet", 10744], + ["og-evm", 10740], ]); // svm