@spheron/protocol-sdk
Version:
Spheron Protocol SDK
2,626 lines (2,615 loc) • 276 kB
JavaScript
import { ethers } from 'ethers';
var ComputeLeaseAbi = [
{
inputs: [
{
internalType: "address",
name: "_orderRequest",
type: "address"
},
{
internalType: "address",
name: "_escrow",
type: "address"
},
{
internalType: "address",
name: "_tokenRegistryAddress",
type: "address"
},
{
internalType: "address",
name: "_resource",
type: "address"
},
{
internalType: "address",
name: "_access",
type: "address"
}
],
stateMutability: "nonpayable",
type: "constructor"
},
{
inputs: [
],
name: "LeaseAlreadyTerminated",
type: "error"
},
{
inputs: [
],
name: "OnlyTenantOrProvider",
type: "error"
},
{
inputs: [
],
name: "ReentrancyGuardReentrantCall",
type: "error"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "uint256",
name: "leaseId",
type: "uint256"
},
{
indexed: false,
internalType: "address",
name: "providerAddress",
type: "address"
},
{
indexed: false,
internalType: "address",
name: "tenantAddress",
type: "address"
}
],
name: "LeaseClosed",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "uint256",
name: "leaseId",
type: "uint256"
}
],
name: "LeaseCreated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "resource",
type: "address"
}
],
name: "ResourceAddressUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "_tokenRegistry",
type: "address"
}
],
name: "TokenRegistryContactUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "escrow",
type: "address"
}
],
name: "escorwAddressUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "orderRequest",
type: "address"
}
],
name: "orderRequestUpdated",
type: "event"
},
{
inputs: [
],
name: "ARB_SYS",
outputs: [
{
internalType: "contract IArbSys",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "accessControl",
outputs: [
{
internalType: "contract IAccessControlManager",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint256",
name: "_leaseId",
type: "uint256"
},
{
internalType: "uint256",
name: "_acceptedPrice",
type: "uint256"
},
{
internalType: "address",
name: "_providerAdress",
type: "address"
}
],
name: "closeAndRenewLease",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint256",
name: "_leaseId",
type: "uint256"
}
],
name: "closeLease",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "_orderId",
type: "uint64"
},
{
internalType: "uint256",
name: "_acceptedPrice",
type: "uint256"
},
{
internalType: "address",
name: "_providerAdress",
type: "address"
},
{
internalType: "uint256",
name: "_fizzId",
type: "uint256"
}
],
name: "createLease",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
],
name: "escrow",
outputs: [
{
internalType: "contract IEscrow",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "getBlockNumber",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint256",
name: "_leaseId",
type: "uint256"
}
],
name: "getLeaseDetails",
outputs: [
{
internalType: "address",
name: "",
type: "address"
},
{
internalType: "address",
name: "",
type: "address"
},
{
internalType: "enum ComputeLease.State",
name: "",
type: "uint8"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_providerAddress",
type: "address"
}
],
name: "getProviderLeases",
outputs: [
{
internalType: "uint256[]",
name: "",
type: "uint256[]"
},
{
internalType: "uint256[]",
name: "",
type: "uint256[]"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_tenantAddress",
type: "address"
}
],
name: "getTenantLeases",
outputs: [
{
internalType: "uint256[]",
name: "",
type: "uint256[]"
},
{
internalType: "uint256[]",
name: "",
type: "uint256[]"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
name: "leases",
outputs: [
{
internalType: "uint256",
name: "leaseId",
type: "uint256"
},
{
internalType: "uint256",
name: "fizzId",
type: "uint256"
},
{
internalType: "uint64",
name: "requestId",
type: "uint64"
},
{
components: [
{
internalType: "int64",
name: "cpuUnits",
type: "int64"
},
{
internalType: "string[]",
name: "cpuAttributes",
type: "string[]"
},
{
internalType: "int64",
name: "ramUnits",
type: "int64"
},
{
internalType: "string[]",
name: "ramAttributes",
type: "string[]"
},
{
internalType: "int64",
name: "gpuUnits",
type: "int64"
},
{
internalType: "string[]",
name: "gpuAttributes",
type: "string[]"
},
{
internalType: "int32",
name: "endpointsKind",
type: "int32"
},
{
internalType: "int32",
name: "endpointsSequenceNumber",
type: "int32"
}
],
internalType: "struct IResourceManager.ResourceAttributes",
name: "resourceAttribute",
type: "tuple"
},
{
internalType: "uint256",
name: "acceptedPrice",
type: "uint256"
},
{
internalType: "address",
name: "providerAddress",
type: "address"
},
{
internalType: "address",
name: "tenantAddress",
type: "address"
},
{
internalType: "uint256",
name: "startBlock",
type: "uint256"
},
{
internalType: "uint256",
name: "startTime",
type: "uint256"
},
{
internalType: "uint256",
name: "endTime",
type: "uint256"
},
{
internalType: "enum ComputeLease.State",
name: "state",
type: "uint8"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "orderRequest",
outputs: [
{
internalType: "contract IOrderRequest",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
},
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
name: "providerLeases",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "resource",
outputs: [
{
internalType: "contract IResourceManager",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
},
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
name: "tenantLeases",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "tokenRegistry",
outputs: [
{
internalType: "contract ITokenRegistry",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_escrow",
type: "address"
}
],
name: "updateEscrowAdress",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_orderRequest",
type: "address"
}
],
name: "updateOrderRequestAdress",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_resource",
type: "address"
}
],
name: "updateResourceAdress",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_tokenRegistry",
type: "address"
}
],
name: "updateTokenRegistryContract",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
}
];
// Testnet Contract Addresses
const AccessControlManagerTestnet = '0x7408e72DaD483859570df578F57f4F61434a8d39';
const TokenRegistryTestnet = '0x30E76950e5eFf7f193FD0a55d86E5249f5f51F7B';
const ProviderRegistryTestnet = '0x840399F9b4CBe04a80facD844c6358d8c2d981fB';
const ProviderAttributeRegistryTestnet = '0x09BCF5BdbD752bA6FD3aB2E4eB8c5b7923d2312C';
const FizzRegistryTestnet = '0x83B06EF4Ae0310682cb90f8b9771A75547b6EBC0';
const FizzAttributeRegistryTestnet = '0x8B4e0fE5C9293855681e518fb9B1c8B0114A0f83';
const EscrowTestnet = '0x4A7aa7e772b53c15cc491247079Dc8B1D814c4af';
const OrderRequestTestnet = '0xBc5D4524518E1af5cbFcFbC7fF0534fa4E59F94b';
const ResourceManagerTestnet = '0xd14F7B393cD5f4eFbBbFDaCe7c45057690Ac1B63';
const ComputeLeaseTestnet = '0x3f1ddD572Fb76FAe1D65c8d11FB9d5f60Bf43257';
const BidTestnet = '0xf04Ba15C07ddA36c49c709375355430F33FEc74C';
const ResourceRegistryCPUTestnet = '0x7aEEE296044c955A707A3A0BB6E1A505bbD15585';
const ResourceRegistryGPUTestnet = '0x01e909Ac5E5D833998bA84a1BB2a16d227A9b3ea';
const ResourceRegistryFactoryTestnet = '0xd6d4C265B3549c4425DF1a15CCEA0634EcB351D2';
const ProviderRewardsManagerTestnet = '0x1b932690a36966C56e89103b786E0bb01bDDDc36';
const FizzRewardsManagerTestnet = '0xB4C78b75c00D1C02409e447B3D78d37BB707913A';
const RewardTokenTestnet = '0xa8ACde36Ec65A5ca286CE5617f0b22F26341B8aE';
// Testnet Token addresses
const USDTTestnet = '0x01e65Ad8F4824037Ed8b3111A6c232D1b8458Bea';
const USDCTestnet = '0xbb132eB1b36D87ef7Ac63c95c05a8a56eCDac3fd';
const DAITestnet = '0x1fFC5C93E3037aa387D3A988e9aCF2Cd11C8B782';
const WETHTestnet = '0xcB66efD46915F97Dd97951a98941ca8d02642aaa';
const contractAddresses = {
testnet: {
accessControlManager: AccessControlManagerTestnet,
tokenRegistry: TokenRegistryTestnet,
providerRegistry: ProviderRegistryTestnet,
providerAttributeRegistry: ProviderAttributeRegistryTestnet,
fizzRegistry: FizzRegistryTestnet,
fizzAttributeRegistry: FizzAttributeRegistryTestnet,
escrow: EscrowTestnet,
orderRequest: OrderRequestTestnet,
resourceManager: ResourceManagerTestnet,
computeLease: ComputeLeaseTestnet,
bid: BidTestnet,
resourceRegistryCPU: ResourceRegistryCPUTestnet,
resourceRegistryGPU: ResourceRegistryGPUTestnet,
resourceRegistryFactory: ResourceRegistryFactoryTestnet,
providerRewardManager: ProviderRewardsManagerTestnet,
fizzRewardManager: FizzRewardsManagerTestnet,
rewardToken: RewardTokenTestnet,
USDT: USDTTestnet,
USDC: USDCTestnet,
DAI: DAITestnet,
WETH: WETHTestnet,
},
mainnet: {
accessControlManager: AccessControlManagerTestnet,
tokenRegistry: TokenRegistryTestnet,
providerRegistry: ProviderRegistryTestnet,
providerAttributeRegistry: ProviderAttributeRegistryTestnet,
fizzRegistry: FizzRegistryTestnet,
fizzAttributeRegistry: FizzAttributeRegistryTestnet,
escrow: EscrowTestnet,
orderRequest: OrderRequestTestnet,
resourceManager: ResourceManagerTestnet,
computeLease: ComputeLeaseTestnet,
bid: BidTestnet,
resourceRegistryCPU: ResourceRegistryCPUTestnet,
resourceRegistryGPU: ResourceRegistryGPUTestnet,
resourceRegistryFactory: ResourceRegistryFactoryTestnet,
providerRewardManager: ProviderRewardsManagerTestnet,
fizzRewardManager: FizzRewardsManagerTestnet,
rewardToken: RewardTokenTestnet,
USDT: USDTTestnet,
USDC: USDCTestnet,
DAI: DAITestnet,
WETH: WETHTestnet,
},
};
var OrderRequestAbi = [
{
inputs: [
{
internalType: "address",
name: "_escrow",
type: "address"
},
{
internalType: "address",
name: "_tokenRegistryAddress",
type: "address"
},
{
internalType: "address",
name: "_access",
type: "address"
},
{
internalType: "uint256",
name: "_maxBlockNumber",
type: "uint256"
}
],
stateMutability: "nonpayable",
type: "constructor"
},
{
inputs: [
],
name: "InsufficientBalance",
type: "error"
},
{
inputs: [
],
name: "InvalidAddress",
type: "error"
},
{
inputs: [
],
name: "InvalidAmount",
type: "error"
},
{
inputs: [
],
name: "InvalidBlockNumber",
type: "error"
},
{
inputs: [
],
name: "InvalidOrderState",
type: "error"
},
{
inputs: [
],
name: "LeaseAlreadyTerminated",
type: "error"
},
{
inputs: [
],
name: "NotAuthorized",
type: "error"
},
{
inputs: [
],
name: "NotBidContract",
type: "error"
},
{
inputs: [
],
name: "OrderNotActive",
type: "error"
},
{
inputs: [
],
name: "OrderNotFound",
type: "error"
},
{
inputs: [
],
name: "OrderNotMatched",
type: "error"
},
{
inputs: [
],
name: "OrderNotOpened",
type: "error"
},
{
inputs: [
],
name: "UnAuthorized",
type: "error"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "lease",
type: "address"
}
],
name: "LeaseAddressUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "uint256",
name: "maxBlockNumber",
type: "uint256"
}
],
name: "MaxBlockNumberUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "uint64",
name: "orderId",
type: "uint64"
},
{
indexed: false,
internalType: "address",
name: "creator",
type: "address"
}
],
name: "OrderCreated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "uint64",
name: "_orderId",
type: "uint64"
}
],
name: "OrderMarkedAsClosed",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "uint64",
name: "_orderId",
type: "uint64"
},
{
indexed: false,
internalType: "address",
name: "provider",
type: "address"
},
{
indexed: false,
internalType: "address",
name: "user",
type: "address"
}
],
name: "OrderUpdateRequested",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "_registryContract",
type: "address"
}
],
name: "TokenRegistryContactUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "escrow",
type: "address"
}
],
name: "escorwAddressUpdated",
type: "event"
},
{
inputs: [
],
name: "accessControl",
outputs: [
{
internalType: "contract IAccessControlManager",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
components: [
{
internalType: "uint256",
name: "maxPrice",
type: "uint256"
},
{
internalType: "uint64",
name: "numOfBlocks",
type: "uint64"
},
{
internalType: "address",
name: "token",
type: "address"
},
{
internalType: "string",
name: "spec",
type: "string"
},
{
internalType: "uint16",
name: "version",
type: "uint16"
},
{
internalType: "enum OrderRequest.Mode",
name: "mode",
type: "uint8"
},
{
internalType: "enum OrderRequest.Tier[]",
name: "tier",
type: "uint8[]"
}
],
internalType: "struct OrderRequest.OrderDetails",
name: "details",
type: "tuple"
}
],
name: "createOrder",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
],
name: "escrow",
outputs: [
{
internalType: "contract IEscrow",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "getAllOrders",
outputs: [
{
components: [
{
internalType: "uint64",
name: "id",
type: "uint64"
},
{
internalType: "uint256",
name: "maxPrice",
type: "uint256"
},
{
internalType: "uint64",
name: "numOfBlocks",
type: "uint64"
},
{
internalType: "address",
name: "token",
type: "address"
},
{
internalType: "address",
name: "creator",
type: "address"
},
{
internalType: "enum OrderRequest.State",
name: "state",
type: "uint8"
},
{
components: [
{
internalType: "string",
name: "specs",
type: "string"
},
{
internalType: "uint16",
name: "version",
type: "uint16"
},
{
internalType: "enum OrderRequest.Mode",
name: "mode",
type: "uint8"
},
{
internalType: "enum OrderRequest.Tier[]",
name: "tier",
type: "uint8[]"
}
],
internalType: "struct OrderRequest.OrderSpecs",
name: "specs",
type: "tuple"
}
],
internalType: "struct OrderRequest.InitialOrder[]",
name: "",
type: "tuple[]"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "_orderId",
type: "uint64"
}
],
name: "getOrderById",
outputs: [
{
components: [
{
internalType: "uint64",
name: "id",
type: "uint64"
},
{
internalType: "uint256",
name: "maxPrice",
type: "uint256"
},
{
internalType: "uint64",
name: "numOfBlocks",
type: "uint64"
},
{
internalType: "address",
name: "token",
type: "address"
},
{
internalType: "address",
name: "creator",
type: "address"
},
{
internalType: "enum OrderRequest.State",
name: "state",
type: "uint8"
},
{
components: [
{
internalType: "string",
name: "specs",
type: "string"
},
{
internalType: "uint16",
name: "version",
type: "uint16"
},
{
internalType: "enum OrderRequest.Mode",
name: "mode",
type: "uint8"
},
{
internalType: "enum OrderRequest.Tier[]",
name: "tier",
type: "uint8[]"
}
],
internalType: "struct OrderRequest.OrderSpecs",
name: "specs",
type: "tuple"
}
],
internalType: "struct OrderRequest.InitialOrder",
name: "",
type: "tuple"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_providerAddress",
type: "address"
}
],
name: "getOrderByProvider",
outputs: [
{
internalType: "uint64[]",
name: "",
type: "uint64[]"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "_orderId",
type: "uint64"
}
],
name: "getPendingOrderById",
outputs: [
{
components: [
{
internalType: "uint64",
name: "id",
type: "uint64"
},
{
internalType: "uint256",
name: "maxPrice",
type: "uint256"
},
{
internalType: "uint64",
name: "numOfBlocks",
type: "uint64"
},
{
internalType: "address",
name: "token",
type: "address"
},
{
internalType: "address",
name: "creator",
type: "address"
},
{
internalType: "enum OrderRequest.State",
name: "state",
type: "uint8"
},
{
components: [
{
internalType: "string",
name: "specs",
type: "string"
},
{
internalType: "uint16",
name: "version",
type: "uint16"
},
{
internalType: "enum OrderRequest.Mode",
name: "mode",
type: "uint8"
},
{
internalType: "enum OrderRequest.Tier[]",
name: "tier",
type: "uint8[]"
}
],
internalType: "struct OrderRequest.OrderSpecs",
name: "specs",
type: "tuple"
}
],
internalType: "struct OrderRequest.InitialOrder",
name: "",
type: "tuple"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "lease",
outputs: [
{
internalType: "contract IComputeLease",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "maxBlockNumber",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "",
type: "uint64"
}
],
name: "orders",
outputs: [
{
internalType: "uint64",
name: "id",
type: "uint64"
},
{
internalType: "uint256",
name: "maxPrice",
type: "uint256"
},
{
internalType: "uint64",
name: "numOfBlocks",
type: "uint64"
},
{
internalType: "address",
name: "token",
type: "address"
},
{
internalType: "address",
name: "creator",
type: "address"
},
{
internalType: "enum OrderRequest.State",
name: "state",
type: "uint8"
},
{
components: [
{
internalType: "string",
name: "specs",
type: "string"
},
{
internalType: "uint16",
name: "version",
type: "uint16"
},
{
internalType: "enum OrderRequest.Mode",
name: "mode",
type: "uint8"
},
{
internalType: "enum OrderRequest.Tier[]",
name: "tier",
type: "uint8[]"
}
],
internalType: "struct OrderRequest.OrderSpecs",
name: "specs",
type: "tuple"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "",
type: "uint64"
},
{
internalType: "uint64",
name: "",
type: "uint64"
}
],
name: "pendingOrders",
outputs: [
{
internalType: "uint64",
name: "id",
type: "uint64"
},
{
internalType: "uint256",
name: "maxPrice",
type: "uint256"
},
{
internalType: "uint64",
name: "numOfBlocks",
type: "uint64"
},
{
internalType: "address",
name: "token",
type: "address"
},
{
internalType: "address",
name: "creator",
type: "address"
},
{
internalType: "enum OrderRequest.State",
name: "state",
type: "uint8"
},
{
components: [
{
internalType: "string",
name: "specs",
type: "string"
},
{
internalType: "uint16",
name: "version",
type: "uint16"
},
{
internalType: "enum OrderRequest.Mode",
name: "mode",
type: "uint8"
},
{
internalType: "enum OrderRequest.Tier[]",
name: "tier",
type: "uint8[]"
}
],
internalType: "struct OrderRequest.OrderSpecs",
name: "specs",
type: "tuple"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint256",
name: "_maxBlockNumber",
type: "uint256"
}
],
name: "setMaxBlockNumber",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
],
name: "tokenRegistry",
outputs: [
{
internalType: "contract ITokenRegistry",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_escrow",
type: "address"
}
],
name: "updateEscrowAdress",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "_orderId",
type: "uint64"
},
{
components: [
{
internalType: "uint256",
name: "maxPrice",
type: "uint256"
},
{
internalType: "uint64",
name: "numOfBlocks",
type: "uint64"
},
{
internalType: "address",
name: "token",
type: "address"
},
{
internalType: "string",
name: "spec",
type: "string"
},
{
internalType: "uint16",
name: "version",
type: "uint16"
},
{
internalType: "enum OrderRequest.Mode",
name: "mode",
type: "uint8"
},
{
internalType: "enum OrderRequest.Tier[]",
name: "tier",
type: "uint8[]"
}
],
internalType: "struct OrderRequest.OrderDetails",
name: "details",
type: "tuple"
}
],
name: "updateInitialOrder",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "_orderId",
type: "uint64"
},
{
internalType: "address",
name: "_providerAddress",
type: "address"
},
{
internalType: "uint256",
name: "_amount",
type: "uint256"
}
],
name: "updateInitialOrderState",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_lease",
type: "address"
}
],
name: "updateLeaseAdress",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "_orderId",
type: "uint64"
}
],
name: "updateOrderStateToClosed",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "_orderId",
type: "uint64"
},
{
internalType: "uint256",
name: "_acceptedPrice",
type: "uint256"
}
],
name: "updatePendingOrder",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_tokenRegistry",
type: "address"
}
],
name: "updateTokenRegistryContract",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
}
];
var BidAbi = [
{
inputs: [
{
internalType: "address",
name: "_providerRegistryAddress",
type: "address"
},
{
internalType: "address",
name: "_fizzRegistryAddress",
type: "address"
},
{
internalType: "address",
name: "_orderRequest",
type: "address"
},
{
internalType: "address",
name: "_lease",
type: "address"
},
{
internalType: "address",
name: "_access",
type: "address"
},
{
internalType: "uint256",
name: "_biddingPeriod",
type: "uint256"
}
],
stateMutability: "nonpayable",
type: "constructor"
},
{
inputs: [
],
name: "BidPriceExceedsMaxPrice",
type: "error"
},
{
inputs: [
],
name: "BiddingClosed",
type: "error"
},
{
inputs: [
],
name: "FizzNodeNotActive",
type: "error"
},
{
inputs: [
],
name: "InvalidAddress",
type: "error"
},
{
inputs: [
],
name: "LeaseNotActive",
type: "error"
},
{
inputs: [
],
name: "OrderNotActive",
type: "error"
},
{
inputs: [
],
name: "OrderNotFound",
type: "error"
},
{
inputs: [
],
name: "ProviderHasActiveBid",
type: "error"
},
{
inputs: [
],
name: "ProviderNotActive",
type: "error"
},
{
inputs: [
],
name: "UnAuthourized",
type: "error"
},
{
inputs: [
],
name: "UpdateOrderNotAccepted",
type: "error"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "uint64",
name: "orderId",
type: "uint64"
},
{
indexed: false,
internalType: "uint256",
name: "bidPrice",
type: "uint256"
},
{
indexed: false,
internalType: "address",
name: "provider",
type: "address"
}
],
name: "BidPlaced",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "fizzRegistry",
type: "address"
}
],
name: "FizzRegistryUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "lease",
type: "address"
}
],
name: "LeaseAddressUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "uint64",
name: "orderId",
type: "uint64"
},
{
indexed: false,
internalType: "address",
name: "providerAddress",
type: "address"
},
{
indexed: false,
internalType: "uint256",
name: "providerId",
type: "uint256"
},
{
indexed: false,
internalType: "uint256",
name: "acceptedPrice",
type: "uint256"
},
{
indexed: false,
internalType: "address",
name: "creator",
type: "address"
}
],
name: "OrderMatched",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "providerRegistry",
type: "address"
}
],
name: "ProviderRegistryUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "uint64",
name: "orderId",
type: "uint64"
},
{
indexed: false,
internalType: "address",
name: "providerAddress",
type: "address"
},
{
indexed: false,
internalType: "address",
name: "tenant",
type: "address"
}
],
name: "UpdateRequestAccepted",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "uint64",
name: "orderId",
type: "uint64"
},
{
indexed: false,
internalType: "address",
name: "providerAddress",
type: "address"
},
{
indexed: false,
internalType: "address",
name: "tenant",
type: "address"
}
],
name: "leaseUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "orderRequest",
type: "address"
}
],
name: "orderRequestAddressUpdated",
type: "event"
},
{
inputs: [
{
internalType: "uint64",
name: "_orderId",
type: "uint64"
}
],
name: "acceptUpdate",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
],
name: "accessControl",
outputs: [
{
internalType: "contract IAccessControlManager",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "biddingPeriod",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "",
type: "uint64"
},
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
name: "bids",
outputs: [
{
internalType: "uint256",
name: "requestId",
type: "uint256"
},
{
internalType: "address",
name: "provider",
type: "address"
},
{
internalType: "uint256",
name: "bidPrice",
type: "uint256"
},
{
internalType: "uint256",
name: "fizzId",
type: "uint256"
},
{
internalType: "uint256",
name: "timestamp",
type: "uint256"
},
{
internalType: "enum Bid.BidState",
name: "state",
type: "uint8"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "fizzRegistry",
outputs: [
{
internalType: "contract IFizzRegistry",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "_orderId",
type: "uint64"
}
],
name: "getAllBidsForOrder",
outputs: [
{
components: [
{
internalType: "uint256",
name: "requestId",
type: "uint256"
},
{
internalType: "address",
name: "provider",
type: "address"
},
{
internalType: "uint256",
name: "bidPrice",
type: "uint256"
},
{
internalType: "uint256",
name: "fizzId",
type: "uint256"
},
{
internalType: "uint256",
name: "timestamp",
type: "uint256"
},
{
internalType: "enum Bid.BidState",
name: "state",
type: "uint8"
}
],
internalType: "struct Bid.ProviderBid[]",
name: "",
type: "tuple[]"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "_orderId",
type: "uint64"
},
{
internalType: "address",
name: "_provider",
type: "address"
}
],
name: "getProviderOrderBid",
outputs: [
{
components: [
{
internalType: "uint256",
name: "requestId",
type: "uint256"
},
{
internalType: "address",
name: "provider",
type: "address"
},
{
internalType: "uint256",
name: "bidPrice",
type: "uint256"
},
{
internalType: "uint256",
name: "fizzId",
type: "uint256"
},
{
internalType: "uint256",
name: "timestamp",
type: "uint256"
},
{
internalType: "enum Bid.BidState",
name: "state",
type: "uint8"
}
],
internalType: "struct Bid.ProviderBid",
name: "",
type: "tuple"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "lease",
outputs: [
{
internalType: "contract IComputeLease",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "_orderId",
type: "uint64"
},
{
internalType: "address",
name: "_providerAddress",
type: "address"
},
{
internalType: "uint256",
name: "_acceptedPrice",
type: "uint256"
}
],
name: "matchOrder",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
],
name: "orderRequest",
outputs: [
{
internalType: "contract IOrderRequest",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
},
{
internalType: "uint64",
name: "",
type: "uint64"
}
],
name: "orderUpdateAcceptance",
outputs: [
{
internalType: "bool",
name: "",
type: "bool"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "_orderId",
type: "uint64"
},
{
internalType: "uint256",
name: "_bidPrice",
type: "uint256"
},
{
internalType: "uint256",
name: "_fizzId",
type: "uint256"
}
],
name: "placeBid",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
},
{
internalType: "uint64",
name: "",
type: "uint64"
}
],
name: "providerActiveBid",
outputs: [
{
internalType: "uint64",
name: "",
type: "uint64"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
},
{
internalType: "uint64",
name: "",
type: "uint64"
}
],
name: "providerOrderBid",
outputs: [
{
internalType: "uint256",
name: "requestId",
type: "uint256"
},
{
internalType: "address",
name: "provider",
type: "address"
},
{
internalType: "uint256",
name: "bidPrice",
type: "uint256"
},
{
internalType: "uint256",
name: "fizzId",
type: "uint256"
},
{
internalType: "uint256",
name: "timestamp",
type: "uint256"
},
{
internalType: "enum Bid.BidState",
name: "state",
type: "uint8"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
],
name: "providerRegistry",
outputs: [
{
internalType: "contract IProviderRegistry",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint256",
name: "_newBiddingPeriod",
type: "uint256"
}
],
name: "setBiddingPeriod",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_fizzRegistry",
type: "address"
}
],
name: "updateFizzRegistryAddress",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_lease",
type: "address"
}
],
name: "updateLeaseAdress",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint64",
name: "_orderId",
type: "uint64"
},
{
internalType: "uint256",
name: "_acceptedPrice",
type: "uint256"
}
],
name: "updateOrder",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_orderRequest",
type: "address"
}
],
name: "updateOrderRequestAdress",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_providerRegistry",
type: "address"
}
],
name: "updateProviderAdress",
outputs: [
],
stateMutability: "nonpayable",
type: "function"
}
];
// Testnet URLs
// export const SPHERON_DEVNET_HTTP_URL = 'https://spheron-devnet-eth.rpc.caldera.xyz/http';
const SPHERON_DEVNET_HTTP_URL = 'https://spheron-devnet-eth.rpc.caldera.xyz/infra-partner-http';
const SPHERON_DEVNET_WSS_URL = 'wss://spheron-devnet-eth.rpc.caldera.xyz/ws';
const SPHERON_DEVNET_EXPLORER_URL = 'https://spheron-devnet-eth.explorer.caldera.xyz';
const rpcUrls = {
testnet: {
HTTP_URL: SPHERON_DEVNET_HTTP_URL,
WSS_URL: SPHERON_DEVNET_WSS_URL,
EXPORER_URL: SPHERON_DEVNET_EXPLORER_URL,
},
mainnet: {
HTTP_URL: SPHERON_DEVNET_HTTP_URL,
WSS_URL: SPHERON_DEVNET_WSS_URL,
EXPORER_URL: SPHERON_DEVNET_EXPLORER_URL,
},
};
const tokenMap = {
testnet: [
{
id: 1,
name: 'Tether USD Test Token',
symbol: 'USDT',
decimal: 6,
address: contractAddresses.testnet.USDT,
// logo: USDTIcon,
},
{
id: 2,
name: 'DAI Test Token',
symbol: 'DAI',
decimal: 18,
address: contractAddresses.testnet.DAI,
// logo: DaiIcon,
},
{
id: 3,
name: 'Test Token USD Coin',
symbol: 'USDC',
decimal: 6,
address: contractAddresses.testnet.USDC,
// logo: USDCIcon,
},
{
id: 4,
name: 'Wrapped ETH Test Token',
symbol: 'WETH',
decimal: 18,
address: contractAddresses.testnet.WETH,
// logo: WethIcon,
},
],
mainnet: [],
};
const networkType = process.env.NETWORK_TYPE || 'testnet';
const DEFAULT_PAGE_SIZE = 10;
const GSEQ = '1';
const OSEQ = '1';
const isValidEthereumAddress = (address) => ethers.isAddress(address);
const getTokenDetails = (tokenAddress, networkType) => {
return (tokenMap[networkType]?.find((token) => token.address.toLowerCase() === tokenAddress.toLowerCase()) || tokenMap[networkType][0]);
};
const requestPipeline = async ({ url, method, body = undefined, }) => {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
const res = await fetch(`${url}`, {
headers,
method,
body,
});
const contentType = res.headers.get('Content-Type');
const isJson = contentType && contentType.includes('application/json');
if (res.status === 204 || res.status === 205) {
return null;
}
else if (isJson) {
return res.json();
}
else {
return res.text();
}
};
const initializeSigner = async ({ wallet }) => {
if (wallet) {
return { signer: wallet };
}
if (typeof window?.ethereum === 'undefined') {
throw new Error('Please install MetaMask');
}
try {
await window.ethereum.request({ method: 'eth_requestAccounts' });
}
catch (error) {
throw new Error('Failed to request Ethereum accounts ->' + error);
}
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
return { signer };
};
var Tier$1;
(function (Tier) {
Tier[Tier["One"] = 0] = "One";
Tier[Tier["Two"] = 1] = "Two";
Tier[Tier["Three"] = 2] = "Three";
Tier[Tier["Four"] = 3] = "Four";
Tier[Tier["Five"] = 4] = "Five";
Tier[Tier["Six"] = 5] = "Six";
Tier[Tier["Seven"] = 6] = "Seven";
})(Tier$1 || (Tier$1 = {}));
var Mode;
(function (Mode) {
Mode[Mode["Fizz"] = 0] = "Fizz";
Mode[Mode["Provider"] = 1] = "Provider";
})(Mode || (Mode = {}));
var OrderState;
(function (OrderState) {
OrderState["OPEN"] = "open";
OrderState["PROVISIONED"] = "provisioned";
OrderState["CLOSED"] = "closed";
OrderState["MATCHED"] = "matched";
})(OrderState || (OrderState = {}));
const getOrderStateAsString = (state) => {
switch (state) {
case '0':
return OrderState.OPEN;
case '1':
return OrderState.PROVISIONED;
case '2':
return OrderState.CLOSED;
case '3':
return OrderState.MATCHED;
}
};
const errorMessages = {
// Escrow Contract Error Messages
TokenAlreadyRegistered: 'This token has already been registered.',
InvalidTokenAddress: 'The token address provided seems to be invalid.',
InvalidOwnerAddress: 'The owner address provided is incorrect or malformed.',
TokenNotRegistered: 'The token you are trying to access is not yet registered in the system. Please register it first.',
// Order Contract Error Messages
OrderNotFound: 'The order you are looking for was not found.',
OrderNotActive: 'The order is not active.',
InvalidAmount: 'The provided amount is invalid.',
InvalidBlockNumber: 'The provider duration is invalid.',
InsufficientBalance: 'You do not have sufficient balance in escrow.',
UnAuthorized: 'You are not authorized to perform this action',
// Lease Contract Error Messages
LeaseAlreadyTerminated: 'The lease is already terminated.',
OnlyTenantOrProvider: 'Only Tenant or Provider can close the lease.',
// Fizz Contract Error Messages
FizzAlreadyRegistered: 'This fizz node is already registered.',
StatusUnchanged: 'No changes detected in the fizz status.',
InactiveFizzNode: 'This fizz node is currently inactive.',
InvalidAddress: 'The address provided seems incorrect. Please verify it.',
TokenAlreadyAccepted: 'This token has already been accepted.',
RegistrationFeeNotPaid: 'The fizz registration fee is unpaid.',
UnregisteredToken: 'The token is unregistered.',
FizzNodeNotFound: 'We could not find the fizz node. Double-check the details and try again.',
TokenNotFound: 'The token was not found. Please verify and try again.',
InvalidUnit: 'The specified unit is invalid. Please correct it.',
// Provider Contract Error Messages
ProviderNotFound: 'Unable to locate the provider. Please check the details.',
ProviderNotActive: 'The provider is currently inactive.',
ProviderAlreadyRegistered: 'The provider is already registered.',
InactiveProvider: 'The provider is inactive.',
NotAuthorized: 'You are not authorized to perform this action.',
InvalidAttributes: 'The provided attributes are not valid.',
EmptyArray: 'No data was provided. The array is empty.',
ArrayMismatch: 'The arrays provided do not match.',
};
const handleContractError = (error, abi) => {
if (error.data) {
try {
const iface = new ethers.Interface(abi);
const decodedError = iface.parseError(error.data);
const errorMessage = decodedError ? errorMessages[decodedError?.name] : '';
if (errorMessage) {
console.error(errorMessage);
return errorMessage;
}
else {
console.error('Unhandled error: ', decodedError?.name || '');
return 'An error occurred while processing your transaction.';
}
}
catch (decodeError) {
console.error('Failed to decode the error:', decodeError);
return 'Failed to decode the error.';
}
}
else {
console.error('Transaction failed without revert data:', error);
return 'Transaction failed without revert data.';
}
};
class OrderModule {
constructor(provider, websocketProvider, wallet) {
this.provider = provider;
this.websocketProvider = websocketProvider;
this.createTimeoutId = null;
this.updateTimeoutId = null;
this.wallet = wallet;
}
async createOrder(orderDetails) {
try {
const { signer } = await initializeSigner({ wallet: this.wallet });
const contract = new ethers.Contract(OrderRequestTestnet, OrderRequestAbi, signer);
const tx = await contract.createOrder(orderDetails);
const receipt = await tx.wait();
console.log('Order created successfully');
return receipt;
}
catch (error) {
console.error('Error creating order -> ', error);
const errorMessage = handleContractError(error, OrderRequestAbi);
throw errorMessage;
}
}
async updateOrder(orderId, orderDetails) {
try {
const { signer } = await initializeSigner({ wallet: this.wallet });
const contract = new ethers.Contract(OrderRequestTestnet, OrderRequestAbi, signer);
const tx = await contract.updateInitialOrder(orderId, orderDetails);
const receipt = await tx.wait();
console.log('Order Update Request Sent');
return receipt;
}
catch (error) {
console.error('Error in updating order -> ', error);
const errorMessage = handleContractError(error, OrderRequestAbi);
throw errorMessage;
}
}
async getOrderDetails(leaseId) {
const contractAbi = OrderRequestAbi;
const contractAddress = OrderRequestTestnet;
const contract = new ethers.Contract(contractAddress, contractAbi, this.provider);
const response = await contract.getOrderById(leaseId);
const specs = {
specs: response.specs.specs,
version: response.specs.version,
mode: response.specs.mode,
tier: response.specs.tier.map((t) => Number(t)),
};
const tokenDetails = getTokenDetails(response.token, 'testnet');
const token = {
symbol: tokenDetails?.symbol,
decimal: tokenDetails?.decimal,
address: tokenDetails?.address,
};
return {
id: response.id.toString(),
maxPrice: Number(response.maxPrice),
numOfBlocks: Number(response.numOfBlocks),
token,
creator: response.creator,
state: getOrderStateAsString(response.state),
specs,
};
}
async listenToOrderCreated(timeoutTime = 60000, onSuccessCallback, onFailureCallback) {
if (!this.websocketProvider) {
console.log('Please pass websocket provider in constructor');
return;
}
const { signer } = await initializeSigner({ wallet: this.wallet });
const account = await signer.getAddress();
const contractAbi = BidAbi;
const contractAddress = BidTestnet;
const contract = new ethers.Contract(contractAddress, contractAbi, this.websocketProvider);
return new Promise((resolve, reject) => {
this.createTimeoutId = setTimeout(() => {
contract.off('OrderMatched');
onFailureCallback();
reject({ error: true, msg: 'Order creation Failed' });
}, timeoutTime);
contract.on('OrderMatched', (orderId, providerAddress, providerId, acceptedPrice, creatorAddress) => {
if (creatorAddress.toString().toLowerCase() === account.toString().toLowerCase()) {
onSuccessCallback(orderId, providerAddress, providerId, acceptedPrice, creatorAddress);