Skip to content
Closed
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
55 changes: 55 additions & 0 deletions .github/workflows/deploy-server-og-evm.yml
Original file line number Diff line number Diff line change
@@ -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!"
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,6 @@ vite.config.ts.timestamp-*
.vite/

# walrus config
walrus_config
walrus_config

.DS_Store
6 changes: 4 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ app.get("/supported", async (req: Request, res: Response) => {
kinds.push({
x402Version: 1,
scheme: "exact",
network: "og-devnet",
network: "og-evm",
});
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions typescript/packages/x402/src/facilitator/facilitator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }> {
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions typescript/packages/x402/src/facilitator/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface SettlePayloadJob extends BaseJob {
network: string;
inputHash: string;
outputHash: string;
modelType?: string;
msg: string;
settlement_type: string;
}
Expand Down Expand Up @@ -82,6 +83,7 @@ export class PaymentQueue {
outputHash: string,
msg: string,
settlement_type: string,
model_type?: string,
): Promise<string> {
const id = Math.random().toString(36).substring(7);
const job: SettlePayloadJob = {
Expand All @@ -92,6 +94,7 @@ export class PaymentQueue {
outputHash,
msg,
settlement_type,
modelType: model_type,
timestamp: Date.now(),
};

Expand Down
3 changes: 2 additions & 1 deletion typescript/packages/x402/src/facilitator/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -187,7 +188,7 @@ async function flushBuffer(
}

async function uploadToWalrus(data: string): Promise<string> {
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}`);

Expand Down
4 changes: 2 additions & 2 deletions typescript/packages/x402/src/types/shared/evm/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export const config: Record<string, ChainConfig> = {
usdcAddress: "0xF1815bd50389c46847f0Bda824eC8da914045D14",
usdcName: "Bridged USDC",
},
"10744": {
usdcAddress: "0x48515A4b24f17cadcD6109a9D85a57ba55a619a6",
"10740": {
usdcAddress: "0x094E464A23B90A71a0894D5D1e5D470FfDD074e1",
usdcName: "OUSDC",
},
};
Expand Down
16 changes: 8 additions & 8 deletions typescript/packages/x402/src/types/shared/evm/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 3 additions & 3 deletions typescript/packages/x402/src/types/shared/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const NetworkSchema = z.enum([
"polygon-amoy",
"peaq",
"story",
"og-devnet",
"og-evm",
]);
export type Network = z.infer<typeof NetworkSchema>;

Expand All @@ -35,7 +35,7 @@ export const SupportedEVMNetworks: Network[] = [
"polygon-amoy",
"peaq",
"story",
"og-devnet",
"og-evm",
];
export const EvmNetworkToChainId = new Map<Network, number>([
["abstract", 2741],
Expand All @@ -51,7 +51,7 @@ export const EvmNetworkToChainId = new Map<Network, number>([
["polygon-amoy", 80002],
["peaq", 3338],
["story", 1514],
["og-devnet", 10744],
["og-evm", 10740],
]);

// svm
Expand Down
Loading