diff --git a/README.md b/README.md index c733baa..b0bf979 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,123 @@ # 0G Serving Broker Documentation -## Overview +# Compute Network Customer Interface + +## Inference + +1. add ledger +2. deposit fund (optional) +3. refund fund (optional) +4. list services +5. generate header + 1. transfer fund to sub account +6. call openai SDK +7. verify response + +## FineTuning +1. add ledger +2. deposit fund (optional) +3. refund fund (optional) +4. list services +5. acknowledge provider signer + 1. [`call provider url/v1/quote`] call provider quote api to download quote (contains provider signer) + 2. [`TBD`] verify the quote using third party service (TODO: Jiahao discuss with Phala) + 3. [`call contract`] acknowledge the provider signer in contract +6. [`use 0g storage sdk`] upload dataset, get dataset root hash +7. create task + 1. get preTrained model root hash based on the model + 2. [`call contract`] calculate fee + 3. [`call contract`] transfer fund from ledger to fine-tuning provider + 4. [`call provider url/v1/task`]call provider task creation api to create task +8. [`call provider url/v1/task-progress`] call provider task progress api to get task progress +9. acknowledge encrypted model with root hash + 1. [`call contract`] get deliverable with root hash + 2. [`use 0g storage sdk`] download model, calculate root hash, compare with provided root hash + 3. [`call contract`] acknowledge the model in contract +10. decrypt model + 1. [`call contract`] get deliverable with encryptedSecret + 2. decrypt the encryptedSecret + 3. decrypt model with secret [TODO: Discuss LiuYuan] + +### Structure + +1. Leger structure + + ```solidity + struct Ledger { + address user; + uint availableBalance; + uint totalBalance; + uint[2] inferenceSigner; + string additionalInfo; + address[] inferenceProviders; + address[] fineTuningProviders; + } + ``` + +2. Service structure + + ```solidity + struct Service { + address provider; + string name; + string url; + Quota quota; + uint pricePerToken; + address providerSigner; + bool occupied; + } + ``` + +3. FineTuning account structure + + ```solidity + struct Account { + address user; + address provider; + uint nonce; + uint balance; + uint pendingRefund; + Refund[] refunds; + string additionalInfo; + address providerSigner; + Deliverable[] deliverables; + } -This document provides an overview of the 0G Serving Broker, including setup and usage instructions. + struct Deliverable { + bytes mod[account.ts](src.ts/broker/account.ts)elRootHash; + bytes encryptedSecret; + bool acknowledged; + } + ``` + +### Provider interface + +1. Endpoint: https://github.com/0glabs/0g-serving-broker/blob/main/api/fine-tuning/internal/handler/handler.go#L23 +2. Task Model: https://github.com/0glabs/0g-serving-broker/blob/main/api/fine-tuning/schema/task.go#L12 +3. Task creation example: + + ```bash + curl -X POST http://Domain/v1/task -d '{ + "customerAddress": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "datasetHash": "0xe080961aa45248f8855dbd540fb40c4927b980c6dc773740da79f19c0b2570c2", + "isTurbo": true, + "preTrainedModelHash": "0xe080961aa45248f8855dbd540fb40c4927b980c6dc773740da79f19c0b2570c2", + "trainingParams": "{ +     "CustomerAddress": "0xabc", +     "PreTrainedModelHash": "0x7f2244b25cd2219dfd9d14c052982ecce409356e0f08e839b79796e270d110a7", +     "DatasetHash": "0xaae9b4e031e06f84b20f10ec629f36c57719ea512992a6b7e2baea93f447a5fa", +     "IsTurbo": true, +     "TrainingParams": "{\"num_train_epochs\": 3, \"per_device_train_batch_size\": 16, \"per_device_eval_batch_size\": 16, \"warmup_steps\": 500, \"weight_decay\": 0.01, \"logging_dir\": \"./logs\", \"logging_steps\": 100, \"evaluation_strategy\": \"no\", \"save_strategy\": \"steps\", \"save_steps\": 500, \"eval_steps\": 500, \"load_best_model_at_end\": false, \"metric_for_best_model\": \"accuracy\", \"greater_is_better\": true, \"report_to\": [\"none\"]}" + }" + }' + ``` -## Setup and Usage -To integrate the 0G Serving Broker into your project, follow these steps +## Overview -### Step 1: Install the dependency +This document provides an overview of the 0G Serving Broker, including setup and usage instructions for both inference and finetuning services. The broker allows user to create one ledger that is for all services. + +## Installation To get started, you need to install the `@0glabs/0g-serving-broker` package: @@ -16,7 +125,7 @@ To get started, you need to install the `@0glabs/0g-serving-broker` package: pnpm add @0glabs/0g-serving-broker @types/crypto-js@4.2.2 crypto-js@4.2.0 ``` -### Step 2: Initialize a Broker Instance +## Initialize a Broker Instance The broker instance is initialized with a `signer`. This signer is an instance that implements the `JsonRpcSigner` or `Wallet` interface from the ethers package and is used to sign transactions for a specific Ethereum account. You can create this instance using your private key via the ethers library or use a wallet framework tool like [wagmi](https://wagmi.sh/react/guides/ethers) to initialize the signer. @@ -34,9 +143,45 @@ import { createZGServingNetworkBroker } from '@0glabs/0g-serving-broker' * @throws An error if the broker cannot be initialized. */ const broker = await createZGServingNetworkBroker(signer) + + +``` + +## Setup the account +The first step to use 0G services is to create a ledger, which will be used for all services. + +### Create a ledger + +```typescript +/** +Create a ledger with certain amount of balance +**/ +await broker.addLedger(balance) ``` -### Step 3: List Available Services +### Deposit funds into the ledger + +```typescript +/** + * 'depositFund' deposits a specified amount of funds into ledger + */ +await broker.depositFund(amount) +``` + +### Refund from the ledger + +``` typescript +/** +Refund from ledger +**/ +broker.refund(amount) +``` + +## Inference + +### List available services + +For inferernce, we can list all available services regardless of the hardware quota. ```typescript /** @@ -56,44 +201,12 @@ const broker = await createZGServingNetworkBroker(signer) * model: string; * }; */ -const services = await broker.listService() +const services = await broker.listInferenceService() ``` -### Step 4: Manage Accounts - -Before using the provider's services, you need to create an account specifically for the chosen provider. The provider checks the account balance before responding to requests. If the balance is insufficient, the request will be denied. +### Use inference services -#### 4.1 Create an Account - -```typescript -/** - * 'addAccount' creates a new account in the contract. - * - * @param {string} providerAddress - The address of the provider for whom the account is being created. - * @param {number} balance - The initial balance to be assigned to the new account. The unit is A0GI. - * - * @throws An error if the account creation fails. - */ -await broker.addAccount(providerAddress, balance) -``` - -#### 4.2 Deposit Funds into the Account - -```typescript -/** - * 'depositFund' deposits a specified amount of funds into an existing account. - * - * @param {string} account - The account identifier where the funds will be deposited. - * @param {number} amount - The amount of funds to be deposited. The unit is A0GI. - * - * @throws An error if the deposit fails. - */ -await broker.depositFund(providerAddress, amount) -``` - -### Step 5: Use the Provider's Services - -#### 5.1 Get Service metadata +#### Get service metadata ```typescript /** @@ -109,13 +222,13 @@ await broker.depositFund(providerAddress, amount) * * @throws An error if errors occur during the processing of the request. */ -const { endpoint, model } = await broker.getServiceMetadata( +const { endpoint, model } = await broker.getInferenceServiceMetadata( providerAddress, serviceName ) ``` -#### 5.2 Get Request Headers +#### Get request headers ```typescript /** @@ -134,14 +247,14 @@ const { endpoint, model } = await broker.getServiceMetadata( * * @throws An error if errors occur during the processing of the request. */ -const headers = await broker.getRequestHeaders( +const headers = await broker.getInferenceRequestHeaders( providerAddress, serviceName, content ) ``` -#### 5.3 Send Request +#### Send the request After obtaining the `endpoint`, `model`, and `headers`, you can use client SDKs compatible with the OpenAI interface to make requests. @@ -188,7 +301,7 @@ await fetch(`${endpoint}/chat/completions`, { }) ``` -#### 5.4 Process Responses +#### Process Responses ```typescript /** @@ -211,7 +324,7 @@ await fetch(`${endpoint}/chat/completions`, { * * @throws An error if any issues occur during the processing of the response. */ -const valid = await broker.processResponse( +const valid = await broker.processInferenceResponse( providerAddress, serviceName, content, @@ -240,6 +353,187 @@ const valid = await broker.processResponse( await broker.settleFee(providerAddress, serviceName, fee) ``` -## Interface +## Finetune + +### List available services of a given model + +For finetuning, we retrive all services according to model name. The full model list can be found in [url]. + +``` typescript + +/** +ServiceStructOutput = { + provider: string; + name: string; + url: string; + quota: QuotaStructOutput; + pricePerToken: bigint; + occupied: boolean; +} +** +**/ +const services = await broker.listFinetuneService("llama3-70b") +``` + +### Upload dataset + +``` typescript +/** +Uload data to 0G platform, the respons is + +{ + "id": "file-abc123", + "object": "file", + "bytes": 120000, + "created_at": 1677610602, + "filename": "mydata.jsonl", + "purpose": "fine-tune", +} +**/ + +const openai = new OpenAI({ + baseURL: endpoint, + apiKey: '', +}) + +// mydata.jsonl is prepared by user, and can be validated with scripts we provide for typical finetune jobs +const file = await openai.files.create({ + file: fs.createReadStream("mydata.jsonl"), + purpose: "fine-tune", +}); + +``` + +### Get service metadata + +```typescript +/** + * 'getFinetuneServiceMetadata' returns metadata for the provider service. + * Includes: + * 1. Service endpoint of the provider service + * 2. Model information for the provider service + * + * @param {string} providerAddress - The address of the provider. + * @param {string} serviceName - The name of the service. + * + * @returns { endpoint, model } - Object containing endpoint and model. + * + * @throws An error if errors occur during the processing of the request. + */ +const { endpoint, model } = await broker.getFinetuneServiceMetadata( + providerAddress, + serviceName +) +``` + +### Get request headers + +Create headers for this finetuning job. The fee is estimated and transferred from ledger to finetune account in this phase. + +```typescript +/** + * 'getFinetuneRequestHeaders' generates billing-related headers for the request + * when the user uses the provider service. + * + * In the 0G Serving system, a request with valid billing headers + * is considered a settlement proof and will be used by the provider + * for settlement in contract. + * + * @param {string} providerAddress - The address of the provider. + * @param {string} serviceName - The name of the service. + * @param {string} finetuneDataset - The id of the uploaded dataset + * @param {int} epoch - The epoch of finetuning + + * @returns headers. Records information such as the request fee and user signature. + * + * @throws An error if errors occur during the processing of the request. + */ +``` + +#### Send the request + +After obtaining the `endpoint`, `model`, and `headers`, you can use client SDKs +compatible with the OpenAI interface to make requests. + +**Note**: After receiving the response, you must use `processResponse` as demonstrated in step 5.4 to settle the response fee. Failure to do so will result in subsequent requests being denied due to unpaid fees. If this happens, you can manually settle the fee using `settleFee` as shown in step 5.5. The amount owed will be specified in the error message. + +**Note**: Generated `headers` are valid for a single use only and cannot be reused. + +```typescript +/** + * Any SDK request methods that follow the OpenAI interface specifications can also be used. + * + * Here is an example using the OpenAI TS SDK. + */ + +const request = await broker.sendFinetuneRequest( + providerAddress, + serviceName, + finetuneDataset, + epoch, + ... +) + +``` + +#### Process Responses + +```typescript +/** + * 'processResponse' is used after the user successfully obtains a response from the provider service. + * + * It will settle the fee for the response content. Additionally, if the service is verifiable, + * input the chat ID from the response and 'processResponse' will determine the validity of the + * returned content by checking the provider service's response and corresponding signature associated + * with the chat ID. + * + * @param {string} providerAddress - The address of the provider. + * @param {string} serviceName - The name of the service. + * @param {string} content - The main content returned by the service. For example, in the case of a chatbot service, + * it would be the response text. + * @param {string} jobID - Only for verifiable services. You can provide the chat ID obtained from the response to + * automatically download the response signature. The function will verify the reliability of the response + * using the service's signing address. + * + * @returns A boolean value. True indicates the returned content is valid, otherwise it is invalid. + * + * @throws An error if any issues occur during the processing of the response. + */ +const valid = await broker.retriveFunetuneModel( + providerAddress, + serviceName, + content, + jobID +) + +await broker.downloadFinetuneModel(jobID, "/path/to/model") +await broker.ackFinetuneModel() +``` + +#### Settle Fees Manually + +```typescript +/** + * 'settleFee' is used to settle the fee for the provider service. + * + * Normally, the fee for each request will be automatically settled in 'processResponse'. + * However, if 'processResponse' fails due to network issues or other reasons, + * you can manually call settleFee to settle the fee. + * + * @param {string} providerAddress - The address of the provider. + * @param {string} serviceName - The name of the service. + * @param {number} fee - The fee to be settled. The unit is A0GI. + * + * @returns A promise that resolves when the fee settlement is successful. + * + * @throws An error if any issues occur during the fee settlement process. + */ +await broker.settleFee(providerAddress, serviceName, fee) +``` + -Access the more details of interfaces via opening [index.html](./docs/index.html) in browser. +### Questions +1. Multiple job? +2. Finetune price can be determined at metadata phase? What is the case of not sure about the price? +3. ZG Data storage? +4. openai-style API? diff --git a/package.json b/package.json index 2095321..20d6655 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,7 @@ "version": "0.1.0", "description": "TS SDK for 0G Compute Network", "main": "./lib.commonjs/index.js", - "files": [ - "types", - "lib.commonjs", - "lib.esm", - "wasm" - ], + "files": ["types", "lib.commonjs", "lib.esm", "wasm"], "exports": { "require": "./lib.commonjs/index.js", "import": "./lib.esm/index.mjs" @@ -21,7 +16,7 @@ "format": "prettier --write src.ts/**/*.ts src.ts/*.ts example/**/*.ts", "clean": "rm -rf dist lib.esm lib.commonjs types", "build": "npm run clean && tsc -b tsconfig.commonjs.json tsconfig.types.json && npx rollup -c rollup.config.mjs", - "gen-contract-type": "typechain --target ethers-v6 --node16-modules --out-dir src.ts/contract/serving '../0g-serving-broker/api/libs/0g-serving-contract/artifacts/contracts/Serving.sol/Serving.json'", + "gen-contract-type": "typechain --target ethers-v6 --node16-modules --out-dir src.ts/contract/serving '../0g-serving-broker/api/libs/0g-serving-contract/artifacts/contracts/fine-tune/FineTuneServing.sol/FineTuneServing.json'", "gen-doc": "npx typedoc --tsconfig tsconfig.esm.json", "test": "mocha -r ts-node/register 'src.ts/**/*.test.ts'" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d4d04c7..2d20195 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -56,9 +56,6 @@ dependencies: open-jsonrpc-provider: specifier: ^0.2.1 version: 0.2.1 - rollup-plugin-dts: - specifier: ^6.1.1 - version: 6.1.1(rollup@3.29.5)(typescript@5.6.2) rollup-plugin-polyfill-node: specifier: ^0.13.0 version: 0.13.0(rollup@3.29.5) @@ -88,6 +85,9 @@ devDependencies: rollup: specifier: ^3.29.5 version: 3.29.5 + rollup-plugin-dts: + specifier: ^6.1.1 + version: 6.1.1(rollup@3.29.5)(typescript@5.6.2) ts-jest: specifier: ^29.1.1 version: 29.2.5(@babel/core@7.25.2)(jest@29.7.0)(typescript@5.6.2) @@ -245,6 +245,7 @@ packages: /@babel/highlight@7.24.7: resolution: {integrity: sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==} engines: {node: '>=6.9.0'} + requiresBuild: true dependencies: '@babel/helper-validator-identifier': 7.24.7 chalk: 2.4.2 @@ -3041,6 +3042,7 @@ packages: /js-tokens@4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} + requiresBuild: true /js-yaml@3.14.1: resolution: {integrity: sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==} @@ -3158,7 +3160,6 @@ packages: resolution: {integrity: sha512-+Wri9p0QHMy+545hKww7YAu5NyzF8iomPL/RQazugQ9+Ez4Ic3mERMd8ZTX5rfK944j+560ZJi8iAwgak1Ac7A==} dependencies: '@jridgewell/sourcemap-codec': 1.5.0 - dev: false /make-dir@4.0.0: resolution: {integrity: sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==} @@ -3617,7 +3618,7 @@ packages: typescript: 5.6.2 optionalDependencies: '@babel/code-frame': 7.24.7 - dev: false + dev: true /rollup-plugin-polyfill-node@0.13.0(rollup@3.29.5): resolution: {integrity: sha512-FYEvpCaD5jGtyBuBFcQImEGmTxDTPbiHjJdrYIp+mFIwgXiXabxvKUK7ZT9P31ozu2Tqm9llYQMRWsfvTMTAOw==} diff --git a/src.ts/broker/account.ts b/src.ts/broker/account.ts index da8e7ba..490772d 100644 --- a/src.ts/broker/account.ts +++ b/src.ts/broker/account.ts @@ -3,6 +3,7 @@ import { genKeyPair } from '../settle-signer' import { AddressLike } from 'ethers' import { encryptData, privateKeyToStr } from '../utils' + /** * AccountProcessor contains methods for creating, depositing funds, and retrieving 0G Serving Accounts. */ @@ -73,31 +74,4 @@ export class AccountProcessor extends ZGServingUserBrokerBase { } } - private async createSettleSignerKey(providerAddress: string): Promise<{ - settleSignerPublicKey: [bigint, bigint] - settleSignerEncryptedPrivateKey: string - }> { - try { - // [pri, pub] - const keyPair = await genKeyPair() - const key = `${this.contract.getUserAddress()}_${providerAddress}` - - this.metadata.storeSettleSignerPrivateKey( - key, - keyPair.packedPrivkey - ) - - const settleSignerEncryptedPrivateKey = await encryptData( - this.contract.signer, - privateKeyToStr(keyPair.packedPrivkey) - ) - - return { - settleSignerEncryptedPrivateKey, - settleSignerPublicKey: keyPair.doublePackedPubkey, - } - } catch (error) { - throw error - } - } } diff --git a/src.ts/broker/base.ts b/src.ts/broker/base.ts index 334f288..12ecd6c 100644 --- a/src.ts/broker/base.ts +++ b/src.ts/broker/base.ts @@ -1,17 +1,22 @@ -import { ServingContract } from '../contract' +import { + InferenceServingContract, + FineTuneServingContract, + InferenceServiceStruct, + FineTuneServing, + FineTuneServiceStruct, +} from '../contract' import { Cache, CacheValueTypeEnum, Metadata } from '../storage' -import { ChatBot, Extractor } from '../extractor' -import { ServiceStructOutput } from '../contract/serving/Serving' -import { ServingRequestHeaders } from './request' -import { decryptData, getNonce, strToPrivateKey } from '../utils' -import { PackedPrivkey, Request, signData } from '../settle-signer' +import { ChatBot, Extractor, ModelFineTune } from '../extractor' +import { ServingRequestHeaders } from './inference/request' +import { decryptData, encryptData, getNonce, privateKeyToStr, strToPrivateKey } from '../utils' +import { genKeyPair, PackedPrivkey, Request, signData } from '../settle-signer' export abstract class ZGServingUserBrokerBase { - protected contract: ServingContract + protected contract: any protected metadata: Metadata protected cache: Cache - constructor(contract: ServingContract, metadata: Metadata, cache: Cache) { + constructor(contract: any, metadata: Metadata, cache: Cache) { this.contract = contract this.metadata = metadata this.cache = cache @@ -25,11 +30,80 @@ export abstract class ZGServingUserBrokerBase { return { settleSignerPrivateKey } } + protected a0giToNeuron(value: number): bigint { + const valueStr = value.toFixed(18) + const parts = valueStr.split('.') + + // Handle integer part + const integerPart = parts[0] + let integerPartAsBigInt = BigInt(integerPart) * BigInt(10 ** 18) + + // Handle fractional part if it exists + if (parts.length > 1) { + let fractionalPart = parts[1] + while (fractionalPart.length < 18) { + fractionalPart += '0' + } + if (fractionalPart.length > 18) { + fractionalPart = fractionalPart.slice(0, 18) // Truncate to avoid overflow + } + + const fractionalPartAsBigInt = BigInt(fractionalPart) + integerPartAsBigInt += fractionalPartAsBigInt + } + + return integerPartAsBigInt + } + + protected neuronToA0gi(value: bigint): number { + const divisor = BigInt(10 ** 18) + const integerPart = value / divisor + const remainder = value % divisor + const decimalPart = Number(remainder) / Number(divisor) + + return Number(integerPart) + decimalPart + } + + protected async createSettleSignerKey(providerAddress: string): Promise<{ + settleSignerPublicKey: [bigint, bigint] + settleSignerEncryptedPrivateKey: string + }> { + try { + // [pri, pub] + const keyPair = await genKeyPair() + const key = `${this.contract.getUserAddress()}_${providerAddress}` + + await this.metadata.storeSettleSignerPrivateKey( + key, + keyPair.packedPrivkey + ) + + const settleSignerEncryptedPrivateKey = await encryptData( + this.contract.signer, + privateKeyToStr(keyPair.packedPrivkey) + ) + + return { + settleSignerEncryptedPrivateKey, + settleSignerPublicKey: keyPair.doublePackedPubkey, + } + } catch (error) { + throw error + } + } + +} + +export abstract class ZGInferenceServingUserBroker extends ZGServingUserBrokerBase { + constructor(contract: InferenceServingContract, metadata: Metadata, cache: Cache) { + super(contract, metadata, cache) + } + protected async getService( providerAddress: string, svcName: string, useCache = true - ): Promise { + ): Promise { const key = providerAddress + svcName const cachedSvc = await this.cache.getItem(key) if (cachedSvc && useCache) { @@ -37,12 +111,12 @@ export abstract class ZGServingUserBrokerBase { } try { - const svc = await this.contract.getService(providerAddress, svcName) + const svc: InferenceServiceStruct = await this.contract.getService(providerAddress, svcName) await this.cache.setItem( key, svc, 1 * 60 * 1000, - CacheValueTypeEnum.Service + CacheValueTypeEnum.InferenceService ) return svc } catch (error) { @@ -68,7 +142,7 @@ export abstract class ZGServingUserBrokerBase { } } - protected createExtractor(svc: ServiceStructOutput): Extractor { + protected createExtractor(svc: InferenceServiceStruct): Extractor { switch (svc.serviceType) { case 'chatbot': return new ChatBot(svc) @@ -77,40 +151,6 @@ export abstract class ZGServingUserBrokerBase { } } - protected a0giToNeuron(value: number): bigint { - const valueStr = value.toFixed(18) - const parts = valueStr.split('.') - - // Handle integer part - const integerPart = parts[0] - let integerPartAsBigInt = BigInt(integerPart) * BigInt(10 ** 18) - - // Handle fractional part if it exists - if (parts.length > 1) { - let fractionalPart = parts[1] - while (fractionalPart.length < 18) { - fractionalPart += '0' - } - if (fractionalPart.length > 18) { - fractionalPart = fractionalPart.slice(0, 18) // Truncate to avoid overflow - } - - const fractionalPartAsBigInt = BigInt(fractionalPart) - integerPartAsBigInt += fractionalPartAsBigInt - } - - return integerPartAsBigInt - } - - protected neuronToA0gi(value: bigint): number { - const divisor = BigInt(10 ** 18) - const integerPart = value / divisor - const remainder = value % divisor - const decimalPart = Number(remainder) / Number(divisor) - - return Number(integerPart) + decimalPart - } - async getHeader( providerAddress: string, svcName: string, @@ -170,7 +210,73 @@ export abstract class ZGServingUserBrokerBase { private async calculateInputFees(extractor: Extractor, content: string) { const svc = await extractor.getSvcInfo() const inputCount = await extractor.getInputCount(content) - const inputFee = BigInt(inputCount) * svc.inputPrice + const inputFee = BigInt(inputCount) * svc?.inputPrice return inputFee } } + +export abstract class ZGFineTuneServingUserBroker extends ZGServingUserBrokerBase { + constructor(contract: FineTuneServingContract, metadata?: Metadata, cache?: Cache) { + super(contract, metadata, cache) + } + + protected async getService( + providerAddress: string, + svcName: string, + useCache = true + ): Promise { + const key = providerAddress + svcName + const cachedSvc = await this.cache.getItem(key) + if (cachedSvc && useCache) { + return cachedSvc + } + + try { + const svc: FineTuneServiceStruct = await this.contract.getService(providerAddress, svcName) + await this.cache.setItem( + key, + svc, + 1 * 60 * 1000, + CacheValueTypeEnum.FineTuneService + ) + return svc + } catch (error) { + throw error + } + } + + protected async getExtractor( + providerAddress: string, + svcName: string, + useCache = true + ): Promise { + try { + const svc = await this.getService( + providerAddress, + svcName, + useCache + ) + const extractor = this.createExtractor(svc) + return extractor + } catch (error) { + throw error + } + } + + protected createExtractor(svc: FineTuneServiceStruct): Extractor { + // todo: extract from finetune service? + switch (svc.name) { + case 'finetune': + return new ModelFineTune(svc) + default: + throw new Error('Unknown service type') + } + } + + // private async calculateFee(extractor: Extractor, dataset_hash: string) { + // const svc = await extractor.getSvcInfo() + // const inputCount = await extractor.getInputCount(content) + // const inputFee = BigInt(inputCount) * svc.inputPrice + // return inputFee + // } +} diff --git a/src.ts/broker/broker.ts b/src.ts/broker/broker.ts index 8a6b012..7863dbe 100644 --- a/src.ts/broker/broker.ts +++ b/src.ts/broker/broker.ts @@ -1,10 +1,17 @@ -import { AccountStructOutput, ServingContract } from '../contract' +import { + FineTuneAccountStruct, + InferenceAccountStruct, + FineTuneServingContract, + InferenceServingContract, + LedgerContract, LedgerStructOutput, +} from '../contract' import { JsonRpcSigner, Wallet } from 'ethers' -import { RequestProcessor } from './request' -import { ResponseProcessor } from './response' -import { Verifier } from './verifier' +import { RequestProcessor } from './inference/request' +import { ResponseProcessor } from './inference/response' +import { Verifier } from './inference/verifier' import { AccountProcessor } from './account' -import { ModelProcessor } from './model' +import { LedgerProcessor } from './ledger' +import { ModelProcessor } from './inference/model' import { Metadata } from '../storage' import { Cache } from '../storage' @@ -12,15 +19,22 @@ export class ZGServingNetworkBroker { public requestProcessor!: RequestProcessor public responseProcessor!: ResponseProcessor public verifier!: Verifier - public accountProcessor!: AccountProcessor + public ledgerProcessor!: LedgerProcessor public modelProcessor!: ModelProcessor private signer: JsonRpcSigner | Wallet - private contractAddress: string + private ledgerContractAddr: string + private inferenceContractAddr: string + private finetuneContractAddr: string - constructor(signer: JsonRpcSigner | Wallet, contractAddress: string) { + constructor(signer: JsonRpcSigner | Wallet, + ledgerContractAddr, + inferenceContractAddr, + finetuneContractAddr) { this.signer = signer - this.contractAddress = contractAddress + this.ledgerContractAddr = ledgerContractAddr + this.inferenceContractAddr = inferenceContractAddr + this.finetuneContractAddr = finetuneContractAddr } async initialize() { @@ -30,22 +44,35 @@ export class ZGServingNetworkBroker { } catch (error) { throw error } - const contract = new ServingContract( + const inf_contract = new InferenceServingContract( this.signer, - this.contractAddress, - userAddress + this.inferenceContractAddr, + userAddress, ) + const ft_contract = new FineTuneServingContract( + this.signer, + this.finetuneContractAddr, + userAddress, + ) + const ledger_contract = new LedgerContract( + this.signer, + this.ledgerContractAddr, + userAddress) + const metadata = new Metadata() const cache = new Cache() - this.requestProcessor = new RequestProcessor(contract, metadata, cache) + this.requestProcessor = new RequestProcessor(inf_contract, metadata, cache) this.responseProcessor = new ResponseProcessor( - contract, + inf_contract, metadata, - cache + cache, ) - this.accountProcessor = new AccountProcessor(contract, metadata, cache) - this.modelProcessor = new ModelProcessor(contract, metadata, cache) - this.verifier = new Verifier(contract, metadata, cache) + + this.ledgerProcessor = new LedgerProcessor(ledger_contract, + inf_contract, ft_contract, metadata, cache) + + this.modelProcessor = new ModelProcessor(inf_contract, metadata, cache) + this.verifier = new Verifier(inf_contract, metadata, cache) } /** @@ -54,7 +81,7 @@ export class ZGServingNetworkBroker { * @returns {Promise} A promise that resolves to an array of ServiceStructOutput objects. * @throws An error if the service list cannot be retrieved. */ - public listService = async () => { + public listInferenceService = async () => { try { return await this.modelProcessor.listService() } catch (error) { @@ -62,57 +89,35 @@ export class ZGServingNetworkBroker { } } - /** - * Adds a new account to the contract. - * - * @param {string} providerAddress - The address of the provider for whom the account is being created. - * @param {number} balance - The initial balance to be assigned to the new account. Units are in A0GI. - * - * @throws An error if the account creation fails. - * - * @remarks - * When creating an account, a key pair is also created to sign the request. - */ - public addAccount = async (providerAddress: string, balance: number) => { + public listFineTuneService = async () => { try { - return await this.accountProcessor.addAccount( - providerAddress, - balance + //todo: a predefined list? + } catch (error) { + throw error + } + } + + public addLedger = async (providerAddress: string, balance: number) => { + try { + return await this.ledgerProcessor.addLedger( + balance, ) } catch (error) { throw error } } - /** - * Retrieves the account information for a given provider address. - * - * @param {string} providerAddress - The address of the provider identifying the account. - * - * @returns A promise that resolves to the account information. - * - * @throws Will throw an error if the account retrieval process fails. - */ - public getAccount = async ( - providerAddress: string - ): Promise => { + public getLedger = async (): Promise => { try { - return await this.accountProcessor.getAccount(providerAddress) + return await this.ledgerProcessor.getLedger() } catch (error) { throw error } } - /** - * Deposits a specified amount of funds into the given account. - * - * @param {string} account - The account identifier where the funds will be deposited. - * @param {string} amount - The amount of funds to be deposited. Units are in A0GI. - * @throws An error if the deposit fails. - */ - public depositFund = async (account: string, amount: number) => { + public depositFund = async (amount: number) => { try { - return await this.accountProcessor.depositFund(account, amount) + return await this.ledgerProcessor.depositFund(amount) } catch (error) { throw error } @@ -131,9 +136,9 @@ export class ZGServingNetworkBroker { * * @throws An error if errors occur during the processing of the request. */ - public getServiceMetadata = async ( + public getInferenceServiceMetadata = async ( providerAddress: string, - svcName: string + svcName: string, ): Promise<{ endpoint: string model: string @@ -141,7 +146,7 @@ export class ZGServingNetworkBroker { try { return await this.requestProcessor.getServiceMetadata( providerAddress, - svcName + svcName, ) } catch (error) { throw error @@ -195,13 +200,13 @@ export class ZGServingNetworkBroker { public getRequestHeaders = async ( providerAddress: string, svcName: string, - content: string + content: string, ) => { try { return await this.requestProcessor.getRequestHeaders( providerAddress, svcName, - content + content, ) } catch (error) { throw error @@ -232,14 +237,14 @@ export class ZGServingNetworkBroker { providerAddress: string, svcName: string, content: string, - chatID?: string + chatID?: string, ): Promise => { try { return await this.responseProcessor.processResponse( providerAddress, svcName, content, - chatID + chatID, ) } catch (error) { throw error @@ -256,9 +261,9 @@ export class ZGServingNetworkBroker { * * @throws An error if errors occur during the verification process. */ - public verifyService = async ( + public verifyInferenceService = async ( providerAddress: string, - svcName: string + svcName: string, ): Promise => { try { return await this.verifier.verifyService(providerAddress, svcName) @@ -279,12 +284,12 @@ export class ZGServingNetworkBroker { */ public getSignerRaDownloadLink = async ( providerAddress: string, - svcName: string + svcName: string, ) => { try { return await this.verifier.getSignerRaDownloadLink( providerAddress, - svcName + svcName, ) } catch (error) { throw error @@ -313,13 +318,13 @@ export class ZGServingNetworkBroker { public getChatSignatureDownloadLink = async ( providerAddress: string, svcName: string, - chatID: string + chatID: string, ) => { try { return await this.verifier.getChatSignatureDownloadLink( providerAddress, svcName, - chatID + chatID, ) } catch (error) { throw error @@ -341,21 +346,31 @@ export class ZGServingNetworkBroker { * * @throws An error if any issues occur during the fee settlement process. */ - public settleFee = async ( + public settleFeeForInference = async ( providerAddress: string, svcName: string, - fee: number + fee: number, ): Promise => { try { return await this.responseProcessor.settleFeeWithA0gi( providerAddress, svcName, - fee + fee, ) } catch (error) { throw error } } + + + //todo: API for finetune + /** + */ + + public ackProviderSigner = async(providerAddress: string) => { + + } + } /** @@ -370,9 +385,12 @@ export class ZGServingNetworkBroker { */ export async function createZGServingNetworkBroker( signer: JsonRpcSigner | Wallet, - contractAddress = '0xE7F0998C83a81f04871BEdfD89aB5f2DAcDBf435' + ledgerContractAddr = '0xE7F0998C83a81f04871BEdfD89aB5f2DAcDBf435', + inferenceContractAddr = '0xE7F0998C83a81f04871BEdfD89aB5f2DAcDBf435', + finetuneContractAddr = '0xE7F0998C83a81f04871BEdfD89aB5f2DAcDBf435', ): Promise { - const broker = new ZGServingNetworkBroker(signer, contractAddress) + const broker = new ZGServingNetworkBroker(signer, + ledgerContractAddr, inferenceContractAddr, finetuneContractAddr) try { await broker.initialize() return broker diff --git a/src.ts/broker/finetune/acknowledge.ts b/src.ts/broker/finetune/acknowledge.ts new file mode 100644 index 0000000..c829ef3 --- /dev/null +++ b/src.ts/broker/finetune/acknowledge.ts @@ -0,0 +1,11 @@ +import { ZGFineTuneServingUserBroker } from '../base' +import { FineTuneServingContract } from '../../contract' + + +export class Acknowledge extends ZGFineTuneServingUserBroker { + + constructor(contract: FineTuneServingContract) { + super(contract) + } + +} \ No newline at end of file diff --git a/src.ts/broker/finetune/dataset.ts b/src.ts/broker/finetune/dataset.ts new file mode 100644 index 0000000..6d67063 --- /dev/null +++ b/src.ts/broker/finetune/dataset.ts @@ -0,0 +1,7 @@ +import { ZGFineTuneServingUserBroker } from '../base' + + +export class FineTuneDataSet { + + +} \ No newline at end of file diff --git a/src.ts/broker/finetune/request.ts b/src.ts/broker/finetune/request.ts new file mode 100644 index 0000000..c09df0a --- /dev/null +++ b/src.ts/broker/finetune/request.ts @@ -0,0 +1,13 @@ +import { ZGFineTuneServingUserBroker } from '../base' +import { FineTuneServingContract } from '../../contract' + +export class FTRequestProcessor extends ZGFineTuneServingUserBroker { + + constructor(contract: FineTuneServingContract) { + super(contract) + } + + async createTask() { + + } +} diff --git a/src.ts/broker/finetune/response.ts b/src.ts/broker/finetune/response.ts new file mode 100644 index 0000000..e69de29 diff --git a/src.ts/broker/finetune/verifier.ts b/src.ts/broker/finetune/verifier.ts new file mode 100644 index 0000000..e69de29 diff --git a/src.ts/broker/index.ts b/src.ts/broker/index.ts index 0199f59..8ba8472 100644 --- a/src.ts/broker/index.ts +++ b/src.ts/broker/index.ts @@ -1,7 +1,7 @@ export * from './account' export * from './base' export * from './broker' -export * from './model' -export * from './request' -export * from './response' -export * from './verifier' +export * from './inference/model' +export * from './inference/request' +export * from './inference/response' +export * from './inference/verifier' diff --git a/src.ts/broker/model.ts b/src.ts/broker/inference/model.ts similarity index 65% rename from src.ts/broker/model.ts rename to src.ts/broker/inference/model.ts index 5869a06..5b95ca5 100644 --- a/src.ts/broker/model.ts +++ b/src.ts/broker/inference/model.ts @@ -1,5 +1,5 @@ -import { ServiceStructOutput } from '../contract' -import { ZGServingUserBrokerBase } from './base' +import { InferenceServiceStruct, InferenceServing } from '../../contract' +import { ZGInferenceServingUserBroker, ZGServingUserBrokerBase } from '../base' export enum VerifiabilityEnum { OpML = 'OpML', @@ -12,8 +12,8 @@ export type Verifiability = | VerifiabilityEnum.TeeML | VerifiabilityEnum.ZKML -export class ModelProcessor extends ZGServingUserBrokerBase { - async listService(): Promise { +export class ModelProcessor extends ZGInferenceServingUserBroker { + async listService(): Promise { try { const services = await this.contract.listService() return services diff --git a/src.ts/broker/request.ts b/src.ts/broker/inference/request.ts similarity index 91% rename from src.ts/broker/request.ts rename to src.ts/broker/inference/request.ts index 241f30b..5656e58 100644 --- a/src.ts/broker/request.ts +++ b/src.ts/broker/inference/request.ts @@ -1,4 +1,4 @@ -import { ZGServingUserBrokerBase } from './base' +import { ZGInferenceServingUserBroker } from '../base' /** * ServingRequestHeaders contains headers related to request billing. @@ -46,7 +46,7 @@ export interface ServingRequestHeaders { * It needs to be initialized with createZGServingUserBroker * before use. */ -export class RequestProcessor extends ZGServingUserBrokerBase { +export class RequestProcessor extends ZGInferenceServingUserBroker { async getServiceMetadata( providerAddress: string, svcName: string @@ -66,12 +66,11 @@ export class RequestProcessor extends ZGServingUserBrokerBase { svcName: string, content: string ): Promise { - const headers = await this.getHeader( + return await this.getHeader( providerAddress, svcName, content, BigInt(0) ) - return headers } } diff --git a/src.ts/broker/response.ts b/src.ts/broker/inference/response.ts similarity index 95% rename from src.ts/broker/response.ts rename to src.ts/broker/inference/response.ts index 33fcf26..d75b964 100644 --- a/src.ts/broker/response.ts +++ b/src.ts/broker/inference/response.ts @@ -1,7 +1,7 @@ -import { ServingContract } from '../contract' -import { Extractor } from '../extractor' -import { Cache, Metadata } from '../storage' -import { ZGServingUserBrokerBase } from './base' +import { ServingContract } from '../../contract' +import { Extractor } from '../../extractor' +import { Cache, Metadata } from '../../storage' +import { ZGServingUserBrokerBase } from '../base' import { isVerifiability, VerifiabilityEnum } from './model' import { Verifier } from './verifier' diff --git a/src.ts/broker/verifier.ts b/src.ts/broker/inference/verifier.ts similarity index 98% rename from src.ts/broker/verifier.ts rename to src.ts/broker/inference/verifier.ts index 2b460b8..530472c 100644 --- a/src.ts/broker/verifier.ts +++ b/src.ts/broker/inference/verifier.ts @@ -1,4 +1,4 @@ -import { ZGServingUserBrokerBase } from './base' +import { ZGInferenceServingUserBroker, ZGServingUserBrokerBase } from '../base' import { ethers } from 'ethers' export interface ResponseSignature { @@ -27,7 +27,7 @@ export interface SingerRAVerificationResult { /** * The Verifier class contains methods for verifying service reliability. */ -export class Verifier extends ZGServingUserBrokerBase { +export class Verifier extends ZGInferenceServingUserBroker { async verifyService( providerAddress: string, svcName: string diff --git a/src.ts/broker/ledger.ts b/src.ts/broker/ledger.ts new file mode 100644 index 0000000..553d629 --- /dev/null +++ b/src.ts/broker/ledger.ts @@ -0,0 +1,130 @@ +import { ZGServingUserBrokerBase } from './base' +import { genKeyPair } from '../settle-signer' +import { AddressLike, BigNumberish } from 'ethers' +import { encryptData, privateKeyToStr } from '../utils' +import { FineTuneServingContract, InferenceServingContract, LedgerContract, LedgerStructOutput } from '../contract' +import { Cache, Metadata } from '../storage' +import { AccountProcessor } from '../broker' + +export class LedgerProcessor extends ZGServingUserBrokerBase { + protected finetuneAccount : AccountProcessor + protected inferenceAccount : AccountProcessor + + constructor(contract: LedgerContract, + inf_contract : InferenceServingContract, + ft_contract : FineTuneServingContract, + metadata: Metadata, cache: Cache) { + super(contract, metadata, cache) + this.finetuneAccount = new AccountProcessor(ft_contract, metadata, cache) + this.inferenceAccount = new AccountProcessor(inf_contract, metadata, cache) + } + + async getLedger() : Promise { + try { + return await this.getLedger() + } catch (error) { + throw error + } + } + + async addLedger(balance : number) { + try { + try { + const l = await this.getLedger() + if (l) { + throw new Error( + 'Account already exists, with balance: ' + + this.neuronToA0gi(l.totalBalance) + + ' A0GI' + ) + } + } catch (error) { + // todo: not sure + if (!(error as any).message.includes('LedgerNotexists')) { + throw error + } + } + + // todo: not sure this providerAddr + const { settleSignerPublicKey, settleSignerEncryptedPrivateKey } = + await this.createSettleSignerKey("provider_addr") + + await this.contract.addLedger( + settleSignerPublicKey, + this.a0giToNeuron(balance), + settleSignerEncryptedPrivateKey + ) + } catch (error) { + throw error + } + } + + async depositFund(amount : number) { + try { + this.contract.depositFund(amount) + } catch (error) { + throw error + } + } + + async _transferFund(provider : string, + amount : BigNumberish, + acc, + service) { + try { + const has_account = await acc.getAccount(provider) + if (!has_account) { + await acc.addAccount(provider, 0) + } + + try { + // transfer balance from ledger to account + await this.contract.transferFund(provider, service, amount) + } catch (error) { + throw error + } + } catch (error) { + throw error + } + } + + async _retriveFund(provider : string, service) { + try { + this.contract.retriveFund(provider, service) + } catch (error) { + throw error + } + } + + async transferFundToInf(provider : string, amount : BigNumberish) { + try { + await this._transferFund(provider, amount, this.inferenceAccount, "inference") + } catch (error) { + throw error + } + } + + async transferFundToFT(provider : string, amount : BigNumberish) { + try { + await this._transferFund(provider, amount, this.finetuneAccount, "fine-tune") + } catch (error) { + throw error + } + } + + async retrieveFundFromInf(provider : string) { + try { + await this._retriveFund(provider, "inference") + } catch (error) { + throw error + } + } + + async retrieveFundFromFT(provider : string) { + try { + await this._retriveFund(provider, "fine-tune") + } catch (error) { + throw error + } + } +} \ No newline at end of file diff --git a/src.ts/contract/contract.ts b/src.ts/contract/contract.ts index d997bdf..5941d98 100644 --- a/src.ts/contract/contract.ts +++ b/src.ts/contract/contract.ts @@ -1,9 +1,20 @@ -import { JsonRpcSigner, BigNumberish, AddressLike, Wallet } from 'ethers' -import { Serving, Serving__factory } from './serving' -import { ServiceStructOutput } from './serving/Serving' +import { AddressLike, BigNumberish, JsonRpcSigner, Wallet } from 'ethers' +import { + FineTuneAccountStruct, + FineTuneServiceStruct, + FineTuneServing, + FineTuneServing__factory, InferenceAccountStruct, InferenceServiceStruct, + InferenceServing, + InferenceServing__factory, + QuotaStructOutput, + LedgerManager, + LedgerStructOutput, + LedgerManager__factory +} from './' +import { QuotaStruct } from './finetune/FineTuneServing' -export class ServingContract { - public serving: Serving +export class FineTuneServingContract { + public serving: FineTuneServing public signer: JsonRpcSigner | Wallet private _userAddress: string @@ -13,7 +24,7 @@ export class ServingContract { contractAddress: string, userAddress: string ) { - this.serving = Serving__factory.connect(contractAddress, signer) + this.serving = FineTuneServing__factory.connect(contractAddress, signer) this.signer = signer this._userAddress = userAddress } @@ -22,7 +33,177 @@ export class ServingContract { return this.serving.lockTime() } - async listService(): Promise { + async canExecute(modelName : string, quota : QuotaStructOutput) : Promise { + // TODO: add comparision for quota + return true; + // return quota.cpuCount > 2; + } + + async listService(): Promise { + try { + return await this.serving.getAllServices() + } catch (error) { + throw error + } + } + + async listAccount() : Promise { + try { + return await this.serving.getAllAccounts() + } catch (error) { + throw error + } + } + + async getAccount(provider: AddressLike) : Promise { + try { + const user = this.getUserAddress() + return await this.serving.getAccount(user, provider) + } catch (error) { + throw error + } + } + + async deleteAccount(provider: AddressLike) { + try { + const tx = + await this.serving.deleteAccount(this.getUserAddress(), provider) + + const receipt = await tx.wait() + + if (!receipt || receipt.status !== 1) { + throw new Error('Finetune deleteAccount failed') + } + } catch (error) { + throw error + } + } + + async addOrUpdateService( + name: string, + url: string, + quota: QuotaStruct, + pricePerToken: BigNumberish, + occupied: boolean + ) { + try { + const tx = await this.serving.addOrUpdateService( + name, + url, + quota, + pricePerToken, + occupied + ) + + const receipt = await tx.wait() + + if (!receipt || receipt.status !== 1) { + throw new Error('Finetune addOrUpdateService failed') + } + } catch (error) { + throw error + } + } + + async addAccount( + providerAddress: AddressLike, + signer: [BigNumberish, BigNumberish], + balance: bigint, + settleSignerEncryptedPrivateKey: string + ) { + try { + const tx = await this.serving.addAccount( + this.getUserAddress(), + providerAddress, + signer, + settleSignerEncryptedPrivateKey, + // todo: can we do this for balance? + { + value: balance, + } + ) + + const receipt = await tx.wait() + + if (!receipt || receipt.status !== 1) { + throw new Error('Finetuning addAccount failed') + } + } catch (error) { + throw error + } + } + + async depositFund(providerAddress: AddressLike, balance: string) { + try { + const tx = await this.serving.depositFund( + this.getUserAddress(), + providerAddress, { + value: balance, + }) + + const receipt = await tx.wait() + + if (!receipt || receipt.status !== 1) { + throw new Error('Finetuning depositFund failed') + } + } catch (error) { + throw error + } + } + + async getService( + providerAddress: string, + svcName: string + ): Promise { + try { + return this.serving.getService(providerAddress, svcName) + } catch (error) { + throw error + } + } + + async ackowledgeProvider(provider : AddressLike) { + try { + await this.serving.acknowledgeProviderSigner(provider) + } catch (error) { + throw error + } + } + + async ackowledgeDeliverable(provider : AddressLike, index : BigNumberish) { + try { + await this.serving.acknowledgeDeliverable(provider, index) + } catch (error) { + throw error + } + } + + getUserAddress(): string { + return this._userAddress + } +} + +export class InferenceServingContract { + public serving: InferenceServing + public signer: JsonRpcSigner | Wallet + + private _userAddress: string + + constructor( + signer: JsonRpcSigner | Wallet, + contractAddress: string, + userAddress: string + ) { + this.serving = InferenceServing__factory.connect(contractAddress, signer) + this.signer = signer + this._userAddress = userAddress + } + + lockTime(): Promise { + return this.serving.lockTime() + } + + async listService(): Promise { try { const services = await this.serving.getAllServices() return services @@ -31,20 +212,18 @@ export class ServingContract { } } - async listAccount() { + async listAccount() : Promise { try { - const accounts = await this.serving.getAllAccounts() - return accounts + return await this.serving.getAllAccounts() } catch (error) { throw error } } - async getAccount(provider: AddressLike) { + async getAccount(provider: AddressLike) : Promise { try { const user = this.getUserAddress() - const account = await this.serving.getAccount(user, provider) - return account + return await this.serving.getAccount(user, provider) } catch (error) { throw error } @@ -52,12 +231,13 @@ export class ServingContract { async deleteAccount(provider: AddressLike) { try { - const tx = await this.serving.deleteAccount(provider) + const tx = + await this.serving.deleteAccount(this.getUserAddress(), provider) const receipt = await tx.wait() if (!receipt || receipt.status !== 1) { - const error = new Error('Transaction failed') + const error = new Error('Inference deleteAccount failed') throw error } } catch (error) { @@ -67,12 +247,12 @@ export class ServingContract { async addOrUpdateService( name: string, - serviceType: string, + serviceType : string, url: string, model: string, - verifiability: string, + verifiability : string, inputPrice: BigNumberish, - outputPrice: BigNumberish + outputPrice: BigNumberish, ) { try { const tx = await this.serving.addOrUpdateService( @@ -88,7 +268,7 @@ export class ServingContract { const receipt = await tx.wait() if (!receipt || receipt.status !== 1) { - const error = new Error('Transaction failed') + const error = new Error('Inference addOrUpdateService failed') throw error } } catch (error) { @@ -104,6 +284,7 @@ export class ServingContract { ) { try { const tx = await this.serving.addAccount( + this.getUserAddress(), providerAddress, signer, settleSignerEncryptedPrivateKey, @@ -115,8 +296,7 @@ export class ServingContract { const receipt = await tx.wait() if (!receipt || receipt.status !== 1) { - const error = new Error('Transaction failed') - throw error + throw new Error('Finetuning addAccount failed') } } catch (error) { throw error @@ -125,15 +305,16 @@ export class ServingContract { async depositFund(providerAddress: AddressLike, balance: string) { try { - const tx = await this.serving.depositFund(providerAddress, { - value: balance, - }) + const tx = await this.serving.depositFund( + this.getUserAddress(), + providerAddress, { + value: balance, + }) const receipt = await tx.wait() if (!receipt || receipt.status !== 1) { - const error = new Error('Transaction failed') - throw error + throw new Error('Finetuning depositFund failed') } } catch (error) { throw error @@ -143,7 +324,7 @@ export class ServingContract { async getService( providerAddress: string, svcName: string - ): Promise { + ): Promise { try { return this.serving.getService(providerAddress, svcName) } catch (error) { @@ -155,3 +336,119 @@ export class ServingContract { return this._userAddress } } + +export class LedgerContract { + public ledger: LedgerManager + public signer: JsonRpcSigner | Wallet + + private readonly _userAddress: string + + constructor( + signer: JsonRpcSigner | Wallet, + contractAddress: string, + userAddress: string + ) { + this.ledger = LedgerManager__factory.connect(contractAddress, signer) + this.signer = signer + this._userAddress = userAddress + } + + async addLedger( + signer: [BigNumberish, BigNumberish], + balance: bigint, + settleSignerEncryptedPrivateKey: string + ) { + // todo: what is the meaning for the return [bigint, bigint]? + try { + const tx = await this.ledger.addLedger( + signer, + settleSignerEncryptedPrivateKey, + { + value: balance, + } + ) + + const receipt = await tx.wait() + + if (!receipt || receipt.status !== 1) { + throw new Error('LedgerManager: addLedger failed') + } + } catch (error) { + throw error + } + } + + async depositFund(balance : bigint) { + try { + const tx = await this.ledger.depositFund( + { + value: balance, + } + ) + + const receipt = await tx.wait() + + if (!receipt || receipt.status !== 1) { + throw new Error('LedgerManager: depositFund failed') + } + } catch (error) { + throw error + } + } + + async getLedger() : Promise { + try { + return await this.ledger.getLedger(this.getUserAddress()) + } catch (error) { + throw error + } + } + + async transferFund(providerAddr : AddressLike, + serviceType : string, + amount : BigNumberish) { + try { + const tx = await this.ledger.transferFund(providerAddr, serviceType, amount); + const receipt = await tx.wait(); + if (!receipt || receipt.status !== 1) { + throw new Error('LedgerManager: transferFund failed') + } + + } catch (error) { + throw error + } + } + + // serviceType: inference or fine-tune + async retrieveFund(providers : AddressLike[], + serviceType : string) { + try { + const tx = await this.ledger.retrieveFund(providers, serviceType); + const receipt = await tx.wait(); + if (!receipt || receipt.status !== 1) { + throw new Error('LedgerManager: retrieveFund failed') + } + } catch (error) { + throw error + } + } + + async refund(amount : BigNumberish) { + try { + const tx = await this.ledger.refund(amount); + const receipt = await tx.wait(); + if (!receipt || receipt.status !== 1) { + throw new Error('LedgerManager: refund failed') + } + } catch (error) { + throw error + } + } + + getUserAddress(): string { + return this._userAddress + } + +} + +export type ServiceStructOutput = FineTuneServiceStruct | InferenceServiceStruct diff --git a/src.ts/contract/finetune/FineTuneServing.ts b/src.ts/contract/finetune/FineTuneServing.ts new file mode 100644 index 0000000..62491a0 --- /dev/null +++ b/src.ts/contract/finetune/FineTuneServing.ts @@ -0,0 +1,909 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumberish, + BytesLike, + FunctionFragment, + Result, + Interface, + EventFragment, + AddressLike, + ContractRunner, + ContractMethod, + Listener, +} from "ethers"; +import type { + TypedContractEvent, + TypedDeferredTopicFilter, + TypedEventLog, + TypedLogDescription, + TypedListener, + TypedContractMethod, +} from "./common.js"; + +export type QuotaStruct = { + cpuCount: BigNumberish; + nodeMemory: BigNumberish; + gpuCount: BigNumberish; + nodeStorage: BigNumberish; + gpuType: string; +}; + +export type QuotaStructOutput = [ + cpuCount: bigint, + nodeMemory: bigint, + gpuCount: bigint, + nodeStorage: bigint, + gpuType: string +] & { + cpuCount: bigint; + nodeMemory: bigint; + gpuCount: bigint; + nodeStorage: bigint; + gpuType: string; +}; + +export type RefundStruct = { + index: BigNumberish; + amount: BigNumberish; + createdAt: BigNumberish; + processed: boolean; +}; + +export type RefundStructOutput = [ + index: bigint, + amount: bigint, + createdAt: bigint, + processed: boolean +] & { index: bigint; amount: bigint; createdAt: bigint; processed: boolean }; + +export type DeliverableStruct = { + modelRootHash: BytesLike; + encryptedSecret: BytesLike; + acknowledged: boolean; +}; + +export type DeliverableStructOutput = [ + modelRootHash: string, + encryptedSecret: string, + acknowledged: boolean +] & { modelRootHash: string; encryptedSecret: string; acknowledged: boolean }; + +export type AccountStruct = { + user: AddressLike; + provider: AddressLike; + nonce: BigNumberish; + balance: BigNumberish; + pendingRefund: BigNumberish; + userSigner: [BigNumberish, BigNumberish]; + refunds: RefundStruct[]; + additionalInfo: string; + providerSigner: AddressLike; + providerSignerAcknowledged: boolean; + deliverables: DeliverableStruct[]; +}; + +export type AccountStructOutput = [ + user: string, + provider: string, + nonce: bigint, + balance: bigint, + pendingRefund: bigint, + userSigner: [bigint, bigint], + refunds: RefundStructOutput[], + additionalInfo: string, + providerSigner: string, + providerSignerAcknowledged: boolean, + deliverables: DeliverableStructOutput[] +] & { + user: string; + provider: string; + nonce: bigint; + balance: bigint; + pendingRefund: bigint; + userSigner: [bigint, bigint]; + refunds: RefundStructOutput[]; + additionalInfo: string; + providerSigner: string; + providerSignerAcknowledged: boolean; + deliverables: DeliverableStructOutput[]; +}; + +export type ServiceStruct = { + provider: AddressLike; + name: string; + url: string; + quota: QuotaStruct; + pricePerToken: BigNumberish; + occupied: boolean; +}; + +export type ServiceStructOutput = [ + provider: string, + name: string, + url: string, + quota: QuotaStructOutput, + pricePerToken: bigint, + occupied: boolean +] & { + provider: string; + name: string; + url: string; + quota: QuotaStructOutput; + pricePerToken: bigint; + occupied: boolean; +}; + +export type VerifierInputStruct = { + index: BigNumberish; + signature: BytesLike; + modelRootHash: BytesLike; + encryptedSecret: BytesLike; + taskFee: BigNumberish; + nonce: BigNumberish; + user: AddressLike; +}; + +export type VerifierInputStructOutput = [ + index: bigint, + signature: string, + modelRootHash: string, + encryptedSecret: string, + taskFee: bigint, + nonce: bigint, + user: string +] & { + index: bigint; + signature: string; + modelRootHash: string; + encryptedSecret: string; + taskFee: bigint; + nonce: bigint; + user: string; +}; + +export interface FineTuneServingInterface extends Interface { + getFunction( + nameOrSignature: + | "accountExists" + | "acknowledgeDeliverable" + | "acknowledgeProviderSigner" + | "addAccount" + | "addDeliverable" + | "addOrUpdateService" + | "addProviderSigner" + | "deleteAccount" + | "depositFund" + | "getAccount" + | "getAllAccounts" + | "getAllServices" + | "getService" + | "initialize" + | "initialized" + | "ledgerAddress" + | "lockTime" + | "owner" + | "processRefund" + | "removeService" + | "renounceOwnership" + | "requestRefundAll" + | "settleFees" + | "transferOwnership" + | "updateLockTime" + ): FunctionFragment; + + getEvent( + nameOrSignatureOrTopic: + | "BalanceUpdated" + | "OwnershipTransferred" + | "RefundRequested" + | "ServiceRemoved" + | "ServiceUpdated" + ): EventFragment; + + encodeFunctionData( + functionFragment: "accountExists", + values: [AddressLike, AddressLike] + ): string; + encodeFunctionData( + functionFragment: "acknowledgeDeliverable", + values: [AddressLike, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "acknowledgeProviderSigner", + values: [AddressLike] + ): string; + encodeFunctionData( + functionFragment: "addAccount", + values: [AddressLike, AddressLike, [BigNumberish, BigNumberish], string] + ): string; + encodeFunctionData( + functionFragment: "addDeliverable", + values: [AddressLike, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "addOrUpdateService", + values: [string, string, QuotaStruct, BigNumberish, boolean] + ): string; + encodeFunctionData( + functionFragment: "addProviderSigner", + values: [AddressLike, AddressLike] + ): string; + encodeFunctionData( + functionFragment: "deleteAccount", + values: [AddressLike, AddressLike] + ): string; + encodeFunctionData( + functionFragment: "depositFund", + values: [AddressLike, AddressLike] + ): string; + encodeFunctionData( + functionFragment: "getAccount", + values: [AddressLike, AddressLike] + ): string; + encodeFunctionData( + functionFragment: "getAllAccounts", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getAllServices", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getService", + values: [AddressLike, string] + ): string; + encodeFunctionData( + functionFragment: "initialize", + values: [BigNumberish, AddressLike, AddressLike] + ): string; + encodeFunctionData( + functionFragment: "initialized", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "ledgerAddress", + values?: undefined + ): string; + encodeFunctionData(functionFragment: "lockTime", values?: undefined): string; + encodeFunctionData(functionFragment: "owner", values?: undefined): string; + encodeFunctionData( + functionFragment: "processRefund", + values: [AddressLike, AddressLike] + ): string; + encodeFunctionData( + functionFragment: "removeService", + values: [string] + ): string; + encodeFunctionData( + functionFragment: "renounceOwnership", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "requestRefundAll", + values: [AddressLike, AddressLike] + ): string; + encodeFunctionData( + functionFragment: "settleFees", + values: [VerifierInputStruct] + ): string; + encodeFunctionData( + functionFragment: "transferOwnership", + values: [AddressLike] + ): string; + encodeFunctionData( + functionFragment: "updateLockTime", + values: [BigNumberish] + ): string; + + decodeFunctionResult( + functionFragment: "accountExists", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "acknowledgeDeliverable", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "acknowledgeProviderSigner", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "addAccount", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "addDeliverable", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "addOrUpdateService", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "addProviderSigner", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "deleteAccount", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "depositFund", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "getAccount", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getAllAccounts", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getAllServices", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "getService", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "initialize", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "initialized", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "ledgerAddress", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "lockTime", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "owner", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "processRefund", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "removeService", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "renounceOwnership", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "requestRefundAll", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "settleFees", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "transferOwnership", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "updateLockTime", + data: BytesLike + ): Result; +} + +export namespace BalanceUpdatedEvent { + export type InputTuple = [ + user: AddressLike, + provider: AddressLike, + amount: BigNumberish, + pendingRefund: BigNumberish + ]; + export type OutputTuple = [ + user: string, + provider: string, + amount: bigint, + pendingRefund: bigint + ]; + export interface OutputObject { + user: string; + provider: string; + amount: bigint; + pendingRefund: bigint; + } + export type Event = TypedContractEvent; + export type Filter = TypedDeferredTopicFilter; + export type Log = TypedEventLog; + export type LogDescription = TypedLogDescription; +} + +export namespace OwnershipTransferredEvent { + export type InputTuple = [previousOwner: AddressLike, newOwner: AddressLike]; + export type OutputTuple = [previousOwner: string, newOwner: string]; + export interface OutputObject { + previousOwner: string; + newOwner: string; + } + export type Event = TypedContractEvent; + export type Filter = TypedDeferredTopicFilter; + export type Log = TypedEventLog; + export type LogDescription = TypedLogDescription; +} + +export namespace RefundRequestedEvent { + export type InputTuple = [ + user: AddressLike, + provider: AddressLike, + index: BigNumberish, + timestamp: BigNumberish + ]; + export type OutputTuple = [ + user: string, + provider: string, + index: bigint, + timestamp: bigint + ]; + export interface OutputObject { + user: string; + provider: string; + index: bigint; + timestamp: bigint; + } + export type Event = TypedContractEvent; + export type Filter = TypedDeferredTopicFilter; + export type Log = TypedEventLog; + export type LogDescription = TypedLogDescription; +} + +export namespace ServiceRemovedEvent { + export type InputTuple = [service: AddressLike, name: string]; + export type OutputTuple = [service: string, name: string]; + export interface OutputObject { + service: string; + name: string; + } + export type Event = TypedContractEvent; + export type Filter = TypedDeferredTopicFilter; + export type Log = TypedEventLog; + export type LogDescription = TypedLogDescription; +} + +export namespace ServiceUpdatedEvent { + export type InputTuple = [ + service: AddressLike, + name: string, + url: string, + quota: QuotaStruct, + occupied: boolean + ]; + export type OutputTuple = [ + service: string, + name: string, + url: string, + quota: QuotaStructOutput, + occupied: boolean + ]; + export interface OutputObject { + service: string; + name: string; + url: string; + quota: QuotaStructOutput; + occupied: boolean; + } + export type Event = TypedContractEvent; + export type Filter = TypedDeferredTopicFilter; + export type Log = TypedEventLog; + export type LogDescription = TypedLogDescription; +} + +export interface FineTuneServing extends BaseContract { + connect(runner?: ContractRunner | null): FineTuneServing; + waitForDeployment(): Promise; + + interface: FineTuneServingInterface; + + queryFilter( + event: TCEvent, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + queryFilter( + filter: TypedDeferredTopicFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + on( + event: TCEvent, + listener: TypedListener + ): Promise; + on( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + once( + event: TCEvent, + listener: TypedListener + ): Promise; + once( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + listeners( + event: TCEvent + ): Promise>>; + listeners(eventName?: string): Promise>; + removeAllListeners( + event?: TCEvent + ): Promise; + + accountExists: TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [boolean], + "view" + >; + + acknowledgeDeliverable: TypedContractMethod< + [provider: AddressLike, index: BigNumberish], + [void], + "nonpayable" + >; + + acknowledgeProviderSigner: TypedContractMethod< + [provider: AddressLike], + [void], + "nonpayable" + >; + + addAccount: TypedContractMethod< + [ + user: AddressLike, + provider: AddressLike, + signer: [BigNumberish, BigNumberish], + additionalInfo: string + ], + [void], + "payable" + >; + + addDeliverable: TypedContractMethod< + [user: AddressLike, modelRootHash: BytesLike], + [void], + "nonpayable" + >; + + addOrUpdateService: TypedContractMethod< + [ + name: string, + url: string, + quota: QuotaStruct, + pricePerToken: BigNumberish, + occupied: boolean + ], + [void], + "nonpayable" + >; + + addProviderSigner: TypedContractMethod< + [user: AddressLike, providerSigner: AddressLike], + [void], + "payable" + >; + + deleteAccount: TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [void], + "nonpayable" + >; + + depositFund: TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [void], + "payable" + >; + + getAccount: TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [AccountStructOutput], + "view" + >; + + getAllAccounts: TypedContractMethod<[], [AccountStructOutput[]], "view">; + + getAllServices: TypedContractMethod<[], [ServiceStructOutput[]], "view">; + + getService: TypedContractMethod< + [provider: AddressLike, name: string], + [ServiceStructOutput], + "view" + >; + + initialize: TypedContractMethod< + [_locktime: BigNumberish, owner: AddressLike, _ledgerAddress: AddressLike], + [void], + "nonpayable" + >; + + initialized: TypedContractMethod<[], [boolean], "view">; + + ledgerAddress: TypedContractMethod<[], [string], "view">; + + lockTime: TypedContractMethod<[], [bigint], "view">; + + owner: TypedContractMethod<[], [string], "view">; + + processRefund: TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [ + [bigint, bigint, bigint] & { + totalAmount: bigint; + balance: bigint; + pendingRefund: bigint; + } + ], + "nonpayable" + >; + + removeService: TypedContractMethod<[name: string], [void], "nonpayable">; + + renounceOwnership: TypedContractMethod<[], [void], "nonpayable">; + + requestRefundAll: TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [void], + "nonpayable" + >; + + settleFees: TypedContractMethod< + [verifierInput: VerifierInputStruct], + [void], + "nonpayable" + >; + + transferOwnership: TypedContractMethod< + [newOwner: AddressLike], + [void], + "nonpayable" + >; + + updateLockTime: TypedContractMethod< + [_locktime: BigNumberish], + [void], + "nonpayable" + >; + + getFunction( + key: string | FunctionFragment + ): T; + + getFunction( + nameOrSignature: "accountExists" + ): TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [boolean], + "view" + >; + getFunction( + nameOrSignature: "acknowledgeDeliverable" + ): TypedContractMethod< + [provider: AddressLike, index: BigNumberish], + [void], + "nonpayable" + >; + getFunction( + nameOrSignature: "acknowledgeProviderSigner" + ): TypedContractMethod<[provider: AddressLike], [void], "nonpayable">; + getFunction( + nameOrSignature: "addAccount" + ): TypedContractMethod< + [ + user: AddressLike, + provider: AddressLike, + signer: [BigNumberish, BigNumberish], + additionalInfo: string + ], + [void], + "payable" + >; + getFunction( + nameOrSignature: "addDeliverable" + ): TypedContractMethod< + [user: AddressLike, modelRootHash: BytesLike], + [void], + "nonpayable" + >; + getFunction( + nameOrSignature: "addOrUpdateService" + ): TypedContractMethod< + [ + name: string, + url: string, + quota: QuotaStruct, + pricePerToken: BigNumberish, + occupied: boolean + ], + [void], + "nonpayable" + >; + getFunction( + nameOrSignature: "addProviderSigner" + ): TypedContractMethod< + [user: AddressLike, providerSigner: AddressLike], + [void], + "payable" + >; + getFunction( + nameOrSignature: "deleteAccount" + ): TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [void], + "nonpayable" + >; + getFunction( + nameOrSignature: "depositFund" + ): TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [void], + "payable" + >; + getFunction( + nameOrSignature: "getAccount" + ): TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [AccountStructOutput], + "view" + >; + getFunction( + nameOrSignature: "getAllAccounts" + ): TypedContractMethod<[], [AccountStructOutput[]], "view">; + getFunction( + nameOrSignature: "getAllServices" + ): TypedContractMethod<[], [ServiceStructOutput[]], "view">; + getFunction( + nameOrSignature: "getService" + ): TypedContractMethod< + [provider: AddressLike, name: string], + [ServiceStructOutput], + "view" + >; + getFunction( + nameOrSignature: "initialize" + ): TypedContractMethod< + [_locktime: BigNumberish, owner: AddressLike, _ledgerAddress: AddressLike], + [void], + "nonpayable" + >; + getFunction( + nameOrSignature: "initialized" + ): TypedContractMethod<[], [boolean], "view">; + getFunction( + nameOrSignature: "ledgerAddress" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "lockTime" + ): TypedContractMethod<[], [bigint], "view">; + getFunction( + nameOrSignature: "owner" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "processRefund" + ): TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [ + [bigint, bigint, bigint] & { + totalAmount: bigint; + balance: bigint; + pendingRefund: bigint; + } + ], + "nonpayable" + >; + getFunction( + nameOrSignature: "removeService" + ): TypedContractMethod<[name: string], [void], "nonpayable">; + getFunction( + nameOrSignature: "renounceOwnership" + ): TypedContractMethod<[], [void], "nonpayable">; + getFunction( + nameOrSignature: "requestRefundAll" + ): TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [void], + "nonpayable" + >; + getFunction( + nameOrSignature: "settleFees" + ): TypedContractMethod< + [verifierInput: VerifierInputStruct], + [void], + "nonpayable" + >; + getFunction( + nameOrSignature: "transferOwnership" + ): TypedContractMethod<[newOwner: AddressLike], [void], "nonpayable">; + getFunction( + nameOrSignature: "updateLockTime" + ): TypedContractMethod<[_locktime: BigNumberish], [void], "nonpayable">; + + getEvent( + key: "BalanceUpdated" + ): TypedContractEvent< + BalanceUpdatedEvent.InputTuple, + BalanceUpdatedEvent.OutputTuple, + BalanceUpdatedEvent.OutputObject + >; + getEvent( + key: "OwnershipTransferred" + ): TypedContractEvent< + OwnershipTransferredEvent.InputTuple, + OwnershipTransferredEvent.OutputTuple, + OwnershipTransferredEvent.OutputObject + >; + getEvent( + key: "RefundRequested" + ): TypedContractEvent< + RefundRequestedEvent.InputTuple, + RefundRequestedEvent.OutputTuple, + RefundRequestedEvent.OutputObject + >; + getEvent( + key: "ServiceRemoved" + ): TypedContractEvent< + ServiceRemovedEvent.InputTuple, + ServiceRemovedEvent.OutputTuple, + ServiceRemovedEvent.OutputObject + >; + getEvent( + key: "ServiceUpdated" + ): TypedContractEvent< + ServiceUpdatedEvent.InputTuple, + ServiceUpdatedEvent.OutputTuple, + ServiceUpdatedEvent.OutputObject + >; + + filters: { + "BalanceUpdated(address,address,uint256,uint256)": TypedContractEvent< + BalanceUpdatedEvent.InputTuple, + BalanceUpdatedEvent.OutputTuple, + BalanceUpdatedEvent.OutputObject + >; + BalanceUpdated: TypedContractEvent< + BalanceUpdatedEvent.InputTuple, + BalanceUpdatedEvent.OutputTuple, + BalanceUpdatedEvent.OutputObject + >; + + "OwnershipTransferred(address,address)": TypedContractEvent< + OwnershipTransferredEvent.InputTuple, + OwnershipTransferredEvent.OutputTuple, + OwnershipTransferredEvent.OutputObject + >; + OwnershipTransferred: TypedContractEvent< + OwnershipTransferredEvent.InputTuple, + OwnershipTransferredEvent.OutputTuple, + OwnershipTransferredEvent.OutputObject + >; + + "RefundRequested(address,address,uint256,uint256)": TypedContractEvent< + RefundRequestedEvent.InputTuple, + RefundRequestedEvent.OutputTuple, + RefundRequestedEvent.OutputObject + >; + RefundRequested: TypedContractEvent< + RefundRequestedEvent.InputTuple, + RefundRequestedEvent.OutputTuple, + RefundRequestedEvent.OutputObject + >; + + "ServiceRemoved(address,string)": TypedContractEvent< + ServiceRemovedEvent.InputTuple, + ServiceRemovedEvent.OutputTuple, + ServiceRemovedEvent.OutputObject + >; + ServiceRemoved: TypedContractEvent< + ServiceRemovedEvent.InputTuple, + ServiceRemovedEvent.OutputTuple, + ServiceRemovedEvent.OutputObject + >; + + "ServiceUpdated(address,string,string,tuple,bool)": TypedContractEvent< + ServiceUpdatedEvent.InputTuple, + ServiceUpdatedEvent.OutputTuple, + ServiceUpdatedEvent.OutputObject + >; + ServiceUpdated: TypedContractEvent< + ServiceUpdatedEvent.InputTuple, + ServiceUpdatedEvent.OutputTuple, + ServiceUpdatedEvent.OutputObject + >; + }; +} diff --git a/src.ts/contract/serving/common.ts b/src.ts/contract/finetune/common.ts similarity index 100% rename from src.ts/contract/serving/common.ts rename to src.ts/contract/finetune/common.ts diff --git a/src.ts/contract/finetune/factories/FineTuneServing__factory.ts b/src.ts/contract/finetune/factories/FineTuneServing__factory.ts new file mode 100644 index 0000000..b4c7643 --- /dev/null +++ b/src.ts/contract/finetune/factories/FineTuneServing__factory.ts @@ -0,0 +1,1112 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { + Contract, + ContractFactory, + ContractTransactionResponse, + Interface, +} from "ethers"; +import type { Signer, ContractDeployTransaction, ContractRunner } from "ethers"; +import type { NonPayableOverrides } from "../common.js"; +import type { + FineTuneServing, + FineTuneServingInterface, +} from "../FineTuneServing.js"; + +const _abi = [ + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "AccountExists", + type: "error", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "AccountNotExists", + type: "error", + }, + { + inputs: [ + { + internalType: "string", + name: "reason", + type: "string", + }, + ], + name: "InvalidProofInputs", + type: "error", + }, + { + inputs: [ + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "string", + name: "name", + type: "string", + }, + ], + name: "ServiceNotExist", + type: "error", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "user", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "provider", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "pendingRefund", + type: "uint256", + }, + ], + name: "BalanceUpdated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "previousOwner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "OwnershipTransferred", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "user", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "provider", + type: "address", + }, + { + indexed: true, + internalType: "uint256", + name: "index", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "timestamp", + type: "uint256", + }, + ], + name: "RefundRequested", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "service", + type: "address", + }, + { + indexed: true, + internalType: "string", + name: "name", + type: "string", + }, + ], + name: "ServiceRemoved", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "service", + type: "address", + }, + { + indexed: true, + internalType: "string", + name: "name", + type: "string", + }, + { + indexed: false, + internalType: "string", + name: "url", + type: "string", + }, + { + components: [ + { + internalType: "uint256", + name: "cpuCount", + type: "uint256", + }, + { + internalType: "uint256", + name: "nodeMemory", + type: "uint256", + }, + { + internalType: "uint256", + name: "gpuCount", + type: "uint256", + }, + { + internalType: "uint256", + name: "nodeStorage", + type: "uint256", + }, + { + internalType: "string", + name: "gpuType", + type: "string", + }, + ], + indexed: false, + internalType: "struct Quota", + name: "quota", + type: "tuple", + }, + { + indexed: false, + internalType: "bool", + name: "occupied", + type: "bool", + }, + ], + name: "ServiceUpdated", + type: "event", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "accountExists", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "uint256", + name: "index", + type: "uint256", + }, + ], + name: "acknowledgeDeliverable", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "acknowledgeProviderSigner", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "uint256[2]", + name: "signer", + type: "uint256[2]", + }, + { + internalType: "string", + name: "additionalInfo", + type: "string", + }, + ], + name: "addAccount", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "bytes", + name: "modelRootHash", + type: "bytes", + }, + ], + name: "addDeliverable", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "string", + name: "name", + type: "string", + }, + { + internalType: "string", + name: "url", + type: "string", + }, + { + components: [ + { + internalType: "uint256", + name: "cpuCount", + type: "uint256", + }, + { + internalType: "uint256", + name: "nodeMemory", + type: "uint256", + }, + { + internalType: "uint256", + name: "gpuCount", + type: "uint256", + }, + { + internalType: "uint256", + name: "nodeStorage", + type: "uint256", + }, + { + internalType: "string", + name: "gpuType", + type: "string", + }, + ], + internalType: "struct Quota", + name: "quota", + type: "tuple", + }, + { + internalType: "uint256", + name: "pricePerToken", + type: "uint256", + }, + { + internalType: "bool", + name: "occupied", + type: "bool", + }, + ], + name: "addOrUpdateService", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "providerSigner", + type: "address", + }, + ], + name: "addProviderSigner", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "deleteAccount", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "depositFund", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "getAccount", + outputs: [ + { + components: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "uint256", + name: "nonce", + type: "uint256", + }, + { + internalType: "uint256", + name: "balance", + type: "uint256", + }, + { + internalType: "uint256", + name: "pendingRefund", + type: "uint256", + }, + { + internalType: "uint256[2]", + name: "userSigner", + type: "uint256[2]", + }, + { + components: [ + { + internalType: "uint256", + name: "index", + type: "uint256", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + internalType: "uint256", + name: "createdAt", + type: "uint256", + }, + { + internalType: "bool", + name: "processed", + type: "bool", + }, + ], + internalType: "struct Refund[]", + name: "refunds", + type: "tuple[]", + }, + { + internalType: "string", + name: "additionalInfo", + type: "string", + }, + { + internalType: "address", + name: "providerSigner", + type: "address", + }, + { + internalType: "bool", + name: "providerSignerAcknowledged", + type: "bool", + }, + { + components: [ + { + internalType: "bytes", + name: "modelRootHash", + type: "bytes", + }, + { + internalType: "bytes", + name: "encryptedSecret", + type: "bytes", + }, + { + internalType: "bool", + name: "acknowledged", + type: "bool", + }, + ], + internalType: "struct Deliverable[]", + name: "deliverables", + type: "tuple[]", + }, + ], + internalType: "struct Account", + name: "", + type: "tuple", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getAllAccounts", + outputs: [ + { + components: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "uint256", + name: "nonce", + type: "uint256", + }, + { + internalType: "uint256", + name: "balance", + type: "uint256", + }, + { + internalType: "uint256", + name: "pendingRefund", + type: "uint256", + }, + { + internalType: "uint256[2]", + name: "userSigner", + type: "uint256[2]", + }, + { + components: [ + { + internalType: "uint256", + name: "index", + type: "uint256", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + internalType: "uint256", + name: "createdAt", + type: "uint256", + }, + { + internalType: "bool", + name: "processed", + type: "bool", + }, + ], + internalType: "struct Refund[]", + name: "refunds", + type: "tuple[]", + }, + { + internalType: "string", + name: "additionalInfo", + type: "string", + }, + { + internalType: "address", + name: "providerSigner", + type: "address", + }, + { + internalType: "bool", + name: "providerSignerAcknowledged", + type: "bool", + }, + { + components: [ + { + internalType: "bytes", + name: "modelRootHash", + type: "bytes", + }, + { + internalType: "bytes", + name: "encryptedSecret", + type: "bytes", + }, + { + internalType: "bool", + name: "acknowledged", + type: "bool", + }, + ], + internalType: "struct Deliverable[]", + name: "deliverables", + type: "tuple[]", + }, + ], + internalType: "struct Account[]", + name: "", + type: "tuple[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getAllServices", + outputs: [ + { + components: [ + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "string", + name: "name", + type: "string", + }, + { + internalType: "string", + name: "url", + type: "string", + }, + { + components: [ + { + internalType: "uint256", + name: "cpuCount", + type: "uint256", + }, + { + internalType: "uint256", + name: "nodeMemory", + type: "uint256", + }, + { + internalType: "uint256", + name: "gpuCount", + type: "uint256", + }, + { + internalType: "uint256", + name: "nodeStorage", + type: "uint256", + }, + { + internalType: "string", + name: "gpuType", + type: "string", + }, + ], + internalType: "struct Quota", + name: "quota", + type: "tuple", + }, + { + internalType: "uint256", + name: "pricePerToken", + type: "uint256", + }, + { + internalType: "bool", + name: "occupied", + type: "bool", + }, + ], + internalType: "struct Service[]", + name: "services", + type: "tuple[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "string", + name: "name", + type: "string", + }, + ], + name: "getService", + outputs: [ + { + components: [ + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "string", + name: "name", + type: "string", + }, + { + internalType: "string", + name: "url", + type: "string", + }, + { + components: [ + { + internalType: "uint256", + name: "cpuCount", + type: "uint256", + }, + { + internalType: "uint256", + name: "nodeMemory", + type: "uint256", + }, + { + internalType: "uint256", + name: "gpuCount", + type: "uint256", + }, + { + internalType: "uint256", + name: "nodeStorage", + type: "uint256", + }, + { + internalType: "string", + name: "gpuType", + type: "string", + }, + ], + internalType: "struct Quota", + name: "quota", + type: "tuple", + }, + { + internalType: "uint256", + name: "pricePerToken", + type: "uint256", + }, + { + internalType: "bool", + name: "occupied", + type: "bool", + }, + ], + internalType: "struct Service", + name: "service", + type: "tuple", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_locktime", + type: "uint256", + }, + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "address", + name: "_ledgerAddress", + type: "address", + }, + ], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "initialized", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "ledgerAddress", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "lockTime", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "owner", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "processRefund", + outputs: [ + { + internalType: "uint256", + name: "totalAmount", + type: "uint256", + }, + { + internalType: "uint256", + name: "balance", + type: "uint256", + }, + { + internalType: "uint256", + name: "pendingRefund", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "string", + name: "name", + type: "string", + }, + ], + name: "removeService", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "renounceOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "requestRefundAll", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + components: [ + { + internalType: "uint256", + name: "index", + type: "uint256", + }, + { + internalType: "bytes", + name: "signature", + type: "bytes", + }, + { + internalType: "bytes", + name: "modelRootHash", + type: "bytes", + }, + { + internalType: "bytes", + name: "encryptedSecret", + type: "bytes", + }, + { + internalType: "uint256", + name: "taskFee", + type: "uint256", + }, + { + internalType: "uint256", + name: "nonce", + type: "uint256", + }, + { + internalType: "address", + name: "user", + type: "address", + }, + ], + internalType: "struct VerifierInput", + name: "verifierInput", + type: "tuple", + }, + ], + name: "settleFees", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_locktime", + type: "uint256", + }, + ], + name: "updateLockTime", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, +] as const; + +const _bytecode = + "0x60806040523480156200001157600080fd5b506200001d3362000023565b62000073565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b613a6280620000836000396000f3fe6080604052600436106101665760003560e01c8063715018a6116100d1578063d1d200561161008a578063f51acaea11610064578063f51acaea14610437578063f5cefe4314610457578063fbfa4e1114610477578063fd5908471461049757600080fd5b8063d1d20056146103d7578063daa2dffb146103f7578063f2fde38b1461041757600080fd5b8063715018a61461031d5780638da5cb5b1461033257806397216725146103645780639824899714610384578063a4f66036146103a4578063b4988fd0146103b757600080fd5b806321fe0f301161012357806321fe0f301461025a5780633f54d9731461027c5780634bc3aff41461028f5780634e3c4f22146102a25780635f7069db146102dd5780636c79158d146102fd57600080fd5b806308e93d0a1461016b5780630d668087146101965780630e61d158146101ba578063147500e3146101e7578063158ef93e146102175780631ded73bb14610238575b600080fd5b34801561017757600080fd5b506101806104c4565b60405161018d9190612ea7565b60405180910390f35b3480156101a257600080fd5b506101ac60015481565b60405190815260200161018d565b3480156101c657600080fd5b506101da6101d5366004612fef565b6104d5565b60405161018d91906130f6565b3480156101f357600080fd5b50610207610202366004613109565b61071c565b604051901515815260200161018d565b34801561022357600080fd5b5060005461020790600160a01b900460ff1681565b34801561024457600080fd5b506102586102533660046131d8565b610733565b005b34801561026657600080fd5b5061026f6107e3565b60405161018d91906132ac565b61025861028a366004613109565b6107ef565b61025861029d366004613301565b610880565b3480156102ae57600080fd5b506102c26102bd366004613109565b6108fc565b6040805193845260208401929092529082015260600161018d565b3480156102e957600080fd5b506102586102f8366004613374565b6109c1565b34801561030957600080fd5b50610258610318366004613109565b6109d2565b34801561032957600080fd5b50610258610a08565b34801561033e57600080fd5b506000546001600160a01b03165b6040516001600160a01b03909116815260200161018d565b34801561037057600080fd5b5061025861037f366004613109565b610a1c565b34801561039057600080fd5b5061025861039f366004612fef565b610a52565b6102586103b2366004613109565b610a5f565b3480156103c357600080fd5b506102586103d236600461339e565b610a6c565b3480156103e357600080fd5b5060025461034c906001600160a01b031681565b34801561040357600080fd5b506102586104123660046133da565b610b15565b34801561042357600080fd5b506102586104323660046133da565b610b24565b34801561044357600080fd5b506102586104523660046133f5565b610b9a565b34801561046357600080fd5b50610258610472366004613429565b610be9565b34801561048357600080fd5b5061025861049236600461346a565b610ed3565b3480156104a357600080fd5b506104b76104b2366004613109565b610ee0565b60405161018d9190613483565b60606104d0600361124f565b905090565b6104dd612a3c565b6104e960068484611652565b6040805160c0810190915281546001600160a01b0316815260018201805491929160208401919061051990613496565b80601f016020809104026020016040519081016040528092919081815260200182805461054590613496565b80156105925780601f1061056757610100808354040283529160200191610592565b820191906000526020600020905b81548152906001019060200180831161057557829003601f168201915b505050505081526020016002820180546105ab90613496565b80601f01602080910402602001604051908101604052809291908181526020018280546105d790613496565b80156106245780601f106105f957610100808354040283529160200191610624565b820191906000526020600020905b81548152906001019060200180831161060757829003601f168201915b50505050508152602001600382016040518060a00160405290816000820154815260200160018201548152602001600282015481526020016003820154815260200160048201805461067590613496565b80601f01602080910402602001604051908101604052809291908181526020018280546106a190613496565b80156106ee5780601f106106c3576101008083540402835291602001916106ee565b820191906000526020600020905b8154815290600101906020018083116106d157829003601f168201915b5050509190925250505081526008820154602082015260099091015460ff1615156040909101529392505050565b600061072a60038484611667565b90505b92915050565b61077e338787878080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250600695949392508991508890508761167c565b8560405161078c91906134d0565b6040518091039020336001600160a01b03167f33062556b04f2d601ba4449c1eddd323e0764abaa16546941dea98f564bc3d25878787866040516107d394939291906134ec565b60405180910390a3505050505050565b60606104d0600661176a565b6002546001600160a01b031633146108225760405162461bcd60e51b81526004016108199061353e565b60405180910390fd5b6000806108326003858534611a3e565b91509150826001600160a01b0316846001600160a01b0316600080516020613a0d8339815191528484604051610872929190918252602082015260400190565b60405180910390a350505050565b6002546001600160a01b031633146108aa5760405162461bcd60e51b81526004016108199061353e565b6000806108bc60038787873488611abb565b91509150846001600160a01b0316866001600160a01b0316600080516020613a0d83398151915284846040516107d3929190918252602082015260400190565b600254600090819081906001600160a01b0316331461092d5760405162461bcd60e51b81526004016108199061353e565b6001546109409060039087908790611b17565b6040519295509093509150339084156108fc029085906000818181858888f19350505050158015610975573d6000803e3d6000fd5b50836001600160a01b0316856001600160a01b0316600080516020613a0d83398151915284846040516109b2929190918252602082015260400190565b60405180910390a39250925092565b6109ce6003338484611c52565b5050565b6002546001600160a01b031633146109fc5760405162461bcd60e51b81526004016108199061353e565b6109ce60038383611d52565b610a10611e13565b610a1a6000611e6d565b565b6002546001600160a01b03163314610a465760405162461bcd60e51b81526004016108199061353e565b6109ce60038383611ebd565b6109ce6003833384611f94565b6109ce600383338461205f565b600054600160a01b900460ff1615610ad15760405162461bcd60e51b815260206004820152602260248201527f496e697469616c697a61626c653a20616c726561647920696e697469616c697a604482015261195960f21b6064820152608401610819565b6000805460ff60a01b1916600160a01b179055610aed82611e6d565b60019290925550600280546001600160a01b0319166001600160a01b03909216919091179055565b610b216003338361211f565b50565b610b2c611e13565b6001600160a01b038116610b915760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610819565b610b2181611e6d565b610ba660063383612175565b80604051610bb491906134d0565b6040519081900381209033907f68026479739e3662c0651578523384b94455e79bfb701ce111a3164591ceba7390600090a350565b6000610c07610bfe60e0840160c085016133da565b600390336121bf565b60098101549091506001600160a01b0316610c6f5760405163885e287960e01b815260206004820152602160248201527f70726f7669646572207369676e696e67206164647265737320697320656d70746044820152607960f81b6064820152608401610819565b6009810154600160a01b900460ff161515600003610ce55760405163885e287960e01b815260206004820152602c60248201527f70726f7669646572207369676e696e672061646472657373206973206e6f742060448201526b1858dadb9bdddb195919d95960a21b6064820152608401610819565b8160a0013581600201541115610d4a5760405163885e287960e01b8152602060048201526024808201527f6e6f6e6365206973206c657373207468616e207468652063757272656e74206e6044820152636f6e636560e01b6064820152608401610819565b600081600a01836000013581548110610d6557610d6561357f565b90600052602060002090600302019050828060400190610d859190613595565b604051610d939291906135e2565b60405190819003812090610da89083906135f2565b604051809103902014610dfe5760405163885e287960e01b815260206004820152601860248201527f6d6f64656c20726f6f742068617368206d69736d6174636800000000000000006044820152606401610819565b6009820154600090610e22906001600160a01b0316610e1c86613668565b906121cc565b905080610e725760405163885e287960e01b815260206004820181905260248201527f54454520736574746c656d656e742076616c69646174696f6e206661696c65646044820152606401610819565b610e7f6060850185613595565b600a850180548735908110610e9657610e9661357f565b90600052602060002090600302016001019182610eb492919061376e565b5060a08401356002840155610ecd836080860135612212565b50505050565b610edb611e13565b600155565b610ee8612aab565b610ef4600384846121bf565b604080516101608101825282546001600160a01b039081168252600184015416602082015260028084015482840152600384015460608301526004840154608083015282518084019384905291939260a085019291600585019182845b815481526020019060010190808311610f51575050505050815260200160078201805480602002602001604051908101604052809291908181526020016000905b82821015610feb576000848152602090819020604080516080810182526004860290920180548352600180820154848601526002820154928401929092526003015460ff16151560608301529083529092019101610f92565b50505050815260200160088201805461100390613496565b80601f016020809104026020016040519081016040528092919081815260200182805461102f90613496565b801561107c5780601f106110515761010080835404028352916020019161107c565b820191906000526020600020905b81548152906001019060200180831161105f57829003601f168201915b505050918352505060098201546001600160a01b038116602080840191909152600160a01b90910460ff161515604080840191909152600a84018054825181850281018501909352808352606090940193919290919060009084015b82821015611240578382906000526020600020906003020160405180606001604052908160008201805461110b90613496565b80601f016020809104026020016040519081016040528092919081815260200182805461113790613496565b80156111845780601f1061115957610100808354040283529160200191611184565b820191906000526020600020905b81548152906001019060200180831161116757829003601f168201915b5050505050815260200160018201805461119d90613496565b80601f01602080910402602001604051908101604052809291908181526020018280546111c990613496565b80156112165780601f106111eb57610100808354040283529160200191611216565b820191906000526020600020905b8154815290600101906020018083116111f957829003601f168201915b50505091835250506002919091015460ff16151560209182015290825260019290920191016110d8565b50505091525090949350505050565b6060600061125c8361241b565b9050806001600160401b0381111561127657611276612f25565b6040519080825280602002602001820160405280156112af57816020015b61129c612aab565b8152602001906001900390816112945790505b50915060005b8181101561164b576112c78482612426565b604080516101608101825282546001600160a01b039081168252600184015416602082015260028084015482840152600384015460608301526004840154608083015282518084019384905291939260a085019291600585019182845b815481526020019060010190808311611324575050505050815260200160078201805480602002602001604051908101604052809291908181526020016000905b828210156113be576000848152602090819020604080516080810182526004860290920180548352600180820154848601526002820154928401929092526003015460ff16151560608301529083529092019101611365565b5050505081526020016008820180546113d690613496565b80601f016020809104026020016040519081016040528092919081815260200182805461140290613496565b801561144f5780601f106114245761010080835404028352916020019161144f565b820191906000526020600020905b81548152906001019060200180831161143257829003601f168201915b505050918352505060098201546001600160a01b038116602080840191909152600160a01b90910460ff161515604080840191909152600a84018054825181850281018501909352808352606090940193919290919060009084015b8282101561161357838290600052602060002090600302016040518060600160405290816000820180546114de90613496565b80601f016020809104026020016040519081016040528092919081815260200182805461150a90613496565b80156115575780601f1061152c57610100808354040283529160200191611557565b820191906000526020600020905b81548152906001019060200180831161153a57829003601f168201915b5050505050815260200160018201805461157090613496565b80601f016020809104026020016040519081016040528092919081815260200182805461159c90613496565b80156115e95780601f106115be576101008083540402835291602001916115e9565b820191906000526020600020905b8154815290600101906020018083116115cc57829003601f168201915b50505091835250506002919091015460ff16151560209182015290825260019290920191016114ab565b505050508152505083828151811061162d5761162d61357f565b6020026020010181905250808061164390613843565b9150506112b5565b5050919050565b600061165f84848461244c565b949350505050565b600061165f8461167785856124a0565b6124d3565b600061168887876124df565b905061169488826124d3565b6116e2576116db88826040518060c001604052808b6001600160a01b031681526020018a8152602001898152602001888152602001878152602001600015158152506124f4565b5050611761565b60006116ef89898961244c565b9050600181016116ff888261385c565b506002810161170e878261385c565b508451600382019081556020860151600483015560408601516005830155606086015160068301556080860151869190600784019061174d908261385c565b505050600901805460ff1916831515179055505b50505050505050565b606060006117778361241b565b9050806001600160401b0381111561179157611791612f25565b6040519080825280602002602001820160405280156117ca57816020015b6117b7612a3c565b8152602001906001900390816117af5790505b50915060005b8181101561164b576117e28482612426565b6040805160c0810190915281546001600160a01b0316815260018201805491929160208401919061181290613496565b80601f016020809104026020016040519081016040528092919081815260200182805461183e90613496565b801561188b5780601f106118605761010080835404028352916020019161188b565b820191906000526020600020905b81548152906001019060200180831161186e57829003601f168201915b505050505081526020016002820180546118a490613496565b80601f01602080910402602001604051908101604052809291908181526020018280546118d090613496565b801561191d5780601f106118f25761010080835404028352916020019161191d565b820191906000526020600020905b81548152906001019060200180831161190057829003601f168201915b50505050508152602001600382016040518060a00160405290816000820154815260200160018201548152602001600282015481526020016003820154815260200160048201805461196e90613496565b80601f016020809104026020016040519081016040528092919081815260200182805461199a90613496565b80156119e75780601f106119bc576101008083540402835291602001916119e7565b820191906000526020600020905b8154815290600101906020018083116119ca57829003601f168201915b5050509190925250505081526008820154602082015260099091015460ff1615156040909101528351849083908110611a2257611a2261357f565b602002602001018190525080611a3790613843565b90506117d0565b6000806000611a4d86866124a0565b9050611a5987826124d3565b611a7a57858560405163023280eb60e21b815260040161081992919061391b565b6000611a878888886125c5565b905084816003016000828254611a9d9190613935565b90915550506003810154600490910154909890975095505050505050565b6000806000611aca88886124a0565b9050611ad689826124d3565b15611af8578787604051632cf0675960e21b815260040161081992919061391b565b611b0789828a8a8a8a8a612610565b5092976000975095505050505050565b600080600080611b288888886125c5565b90506000935060005b6007820154811015611c38576000826007018281548110611b5457611b5461357f565b60009182526020909120600490910201600381015490915060ff1615611b7a5750611c26565b868160020154611b8a9190613935565b421015611b975750611c26565b8060010154836003016000828254611baf9190613948565b90915550506001810154600484018054600090611bcd908490613948565b909155505060078301805483908110611be857611be861357f565b60009182526020822060049091020181815560018082018390556002820192909255600301805460ff19169055810154611c229087613935565b9550505b80611c3081613843565b915050611b31565b508060030154925080600401549150509450945094915050565b611c608461167785856124a0565b611c8157828260405163023280eb60e21b815260040161081992919061391b565b6000611c8e8585856125c5565b905080600a018281548110611ca557611ca561357f565b90600052602060002090600302016000018054611cc190613496565b9050600003611d125760405162461bcd60e51b815260206004820152601b60248201527f64656c6976657261626c6520646f6573206e6f742065786973742e00000000006044820152606401610819565b600181600a018381548110611d2957611d2961357f565b60009182526020909120600390910201600201805460ff19169115159190911790555050505050565b6000611d5f8484846125c5565b9050600081600401548260030154611d779190613948565b905080600003611d88575050505050565b6040805160808101825260078401805480835260208084018681524295850195865260006060860181815260018086018755958252928120955160049485029096019586559051938501939093559351600284015592516003909201805460ff1916921515929092179091559083018054839290611e07908490613935565b90915550505050505050565b6000546001600160a01b03163314610a1a5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610819565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000611ec983836124a0565b9050611ed584826124d3565b611ef657828260405163023280eb60e21b815260040161081992919061391b565b611f00848261268b565b50600081815260028086016020526040822080546001600160a01b0319908116825560018201805490911690559081018290556003810182905560048101829055600581018290556006810182905590611f5e600783016000612b1c565b611f6c600883016000612b3d565b6009820180546001600160a81b0319169055611f8c600a83016000612b77565b505050505050565b611fa28461167785856124a0565b611fc357828260405163023280eb60e21b815260040161081992919061391b565b6000611fd08585856125c5565b60408051606081018252848152815160208181018452600080835281840192909252928201819052600a84018054600181018255908252929020815193945090928392600302909101908190612026908261385c565b506020820151600182019061203b908261385c565b50604091909101516002909101805460ff1916911515919091179055505050505050565b61206d8461167785856124a0565b61208e57828260405163023280eb60e21b815260040161081992919061391b565b600061209b8585856125c5565b60098101549091506001600160a01b0316156120f95760405162461bcd60e51b815260206004820152601f60248201527f70726f7669646572207369676e657220616c7265616479206578697374732e006044820152606401610819565b60090180546001600160a01b0319166001600160a01b0392909216919091179055505050565b61212d8361167784846124a0565b61214e57818160405163023280eb60e21b815260040161081992919061391b565b600061215b8484846125c5565b600901805460ff60a01b1916600160a01b17905550505050565b600061218183836124df565b905061218d84826124d3565b6121ae578282604051636e41f4cf60e11b815260040161081992919061395b565b6121b88482612697565b5050505050565b600061165f8484846125c5565b6000806121d88461271c565b905060006121e582612768565b9050836001600160a01b03166121ff8287602001516127a3565b6001600160a01b03161495945050505050565b816004015482600301546122269190613948565b81111561238b576000826004015483600301546122439190613948565b61224d9083613948565b905080836004015410156122b25760405163885e287960e01b815260206004820152602560248201527f696e73756666696369656e742062616c616e636520696e2070656e64696e675260448201526419599d5b9960da1b6064820152608401610819565b808360040160008282546122c69190613948565b909155505060078301546000906122df90600190613948565b90505b600081126123885760008460070182815481106123015761230161357f565b60009182526020909120600490910201600381015490915060ff16156123275750612376565b828160010154116123485760018101546123419084613948565b9250612366565b8281600101600082825461235c9190613948565b9091555060009350505b826000036123745750612388565b505b806123808161397f565b9150506122e2565b50505b8082600301600082825461239f9190613948565b909155505081546003830154600484015460405133936001600160a01b031692600080516020613a0d833981519152926123e192918252602082015260400190565b60405180910390a3604051339082156108fc029083906000818181858888f19350505050158015612416573d6000803e3d6000fd5b505050565b600061072d82612822565b600080612433848461282c565b6000908152600285016020526040902091505092915050565b60008061245984846124df565b6000818152600287016020526040902090915061247686836124d3565b612497578484604051636e41f4cf60e11b815260040161081992919061395b565b95945050505050565b600082826040516020016124b592919061391b565b60405160208183030381529060405280519060200120905092915050565b600061072a8383612838565b600082826040516020016124b592919061395b565b600082815260028401602090815260408220835181546001600160a01b0319166001600160a01b03909116178155908301518391906001820190612538908261385c565b506040820151600282019061254d908261385c565b50606082015181600301600082015181600001556020820151816001015560408201518160020155606082015181600301556080820151816004019081612594919061385c565b5050506080820151600882015560a0909101516009909101805460ff191691151591909117905561165f8484612850565b6000806125d284846124a0565b600081815260028701602052604090209091506125ef86836124d3565b61249757848460405163023280eb60e21b815260040161081992919061391b565b6000868152600280890160205260409091206003810184905580546001600160a01b038089166001600160a01b031992831617835560018301805491891691909216179055906126669060058301908690612b98565b5060088101612675838261385c565b506126808888612850565b505050505050505050565b600061072a838361285c565b6000818152600283016020526040812080546001600160a01b0319168155816126c36001830182612b3d565b6126d1600283016000612b3d565b600060038301818155600484018290556005840182905560068401829055906126fd6007850182612b3d565b50506000600883015550600901805460ff1916905561072a838361268b565b6000816040015182608001518360a001518460c00151856060015160405160200161274b95949392919061399c565b604051602081830303815290604052805190602001209050919050565b6040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c0161274b565b6000806000806127b28561294f565b6040805160008152602081018083528b905260ff8316918101919091526060810184905260808101839052929550909350915060019060a0016020604051602081039080840390855afa15801561280d573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b600061072d825490565b600061072a83836129c3565b6000818152600183016020526040812054151561072a565b600061072a83836129ed565b60008181526001830160205260408120548015612945576000612880600183613948565b855490915060009061289490600190613948565b90508181146128f95760008660000182815481106128b4576128b461357f565b90600052602060002001549050808760000184815481106128d7576128d761357f565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061290a5761290a6139f6565b60019003818190600052602060002001600090559055856001016000868152602001908152602001600020600090556001935050505061072d565b600091505061072d565b600080600083516041146129a55760405162461bcd60e51b815260206004820152601860248201527f696e76616c6964207369676e6174757265206c656e67746800000000000000006044820152606401610819565b50505060208101516040820151606090920151909260009190911a90565b60008260000182815481106129da576129da61357f565b9060005260206000200154905092915050565b6000818152600183016020526040812054612a345750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561072d565b50600061072d565b6040518060c0016040528060006001600160a01b031681526020016060815260200160608152602001612a976040518060a0016040528060008152602001600081526020016000815260200160008152602001606081525090565b815260006020820181905260409091015290565b60405180610160016040528060006001600160a01b0316815260200160006001600160a01b03168152602001600081526020016000815260200160008152602001612af4612bd6565b8152606060208201819052604082018190526000818301819052608083015260a09091015290565b5080546000825560040290600052602060002090810190610b219190612bf4565b508054612b4990613496565b6000825580601f10612b59575050565b601f016020900490600052602060002090810190610b219190612c22565b5080546000825560030290600052602060002090810190610b219190612c37565b8260028101928215612bc6579160200282015b82811115612bc6578235825591602001919060010190612bab565b50612bd2929150612c22565b5090565b60405180604001604052806002906020820280368337509192915050565b5b80821115612bd257600080825560018201819055600282015560038101805460ff19169055600401612bf5565b5b80821115612bd25760008155600101612c23565b80821115612bd2576000612c4b8282612b3d565b612c59600183016000612b3d565b5060028101805460ff19169055600301612c37565b8060005b6002811015610ecd578151845260209384019390910190600101612c72565b600081518084526020808501945080840160005b83811015612ce35781518051885283810151848901526040808201519089015260609081015115159088015260809096019590820190600101612ca5565b509495945050505050565b60005b83811015612d09578181015183820152602001612cf1565b50506000910152565b60008151808452612d2a816020860160208601612cee565b601f01601f19169290920160200192915050565b600082825180855260208086019550808260051b84010181860160005b84811015612dbc57601f19868403018952815160608151818652612d8182870182612d12565b9150508582015185820387870152612d998282612d12565b604093840151151596909301959095525098840198925090830190600101612d5b565b5090979650505050505050565b80516001600160a01b0316825260006101806020830151612df560208601826001600160a01b03169052565b5060408301516040850152606083015160608501526080830151608085015260a0830151612e2660a0860182612c6e565b5060c08301518160e0860152612e3e82860182612c91565b91505060e083015161010085830381870152612e5a8383612d12565b925080850151915050610120612e7a818701836001600160a01b03169052565b8401519050610140612e8f8682018315159052565b84015185830361016087015290506124978282612d3e565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b82811015612efc57603f19888603018452612eea858351612dc9565b94509285019290850190600101612ece565b5092979650505050505050565b80356001600160a01b0381168114612f2057600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60405160e081016001600160401b0381118282101715612f5d57612f5d612f25565b60405290565b600082601f830112612f7457600080fd5b81356001600160401b0380821115612f8e57612f8e612f25565b604051601f8301601f19908116603f01168101908282118183101715612fb657612fb6612f25565b81604052838152866020858801011115612fcf57600080fd5b836020870160208301376000602085830101528094505050505092915050565b6000806040838503121561300257600080fd5b61300b83612f09565b915060208301356001600160401b0381111561302657600080fd5b61303285828601612f63565b9150509250929050565b805182526020810151602083015260408101516040830152606081015160608301526000608082015160a0608085015261165f60a0850182612d12565b60018060a01b0381511682526000602082015160c060208501526130a060c0850182612d12565b9050604083015184820360408601526130b98282612d12565b915050606083015184820360608601526130d3828261303c565b9150506080830151608085015260a0830151151560a08501528091505092915050565b60208152600061072a6020830184613079565b6000806040838503121561311c57600080fd5b61312583612f09565b915061313360208401612f09565b90509250929050565b600060a0828403121561314e57600080fd5b60405160a081016001600160401b03828210818311171561317157613171612f25565b816040528293508435835260208501356020840152604085013560408401526060850135606084015260808501359150808211156131ae57600080fd5b506131bb85828601612f63565b6080830152505092915050565b80358015158114612f2057600080fd5b60008060008060008060a087890312156131f157600080fd5b86356001600160401b038082111561320857600080fd5b6132148a838b01612f63565b9750602089013591508082111561322a57600080fd5b818901915089601f83011261323e57600080fd5b81358181111561324d57600080fd5b8a602082850101111561325f57600080fd5b60208301975080965050604089013591508082111561327d57600080fd5b5061328a89828a0161313c565b935050606087013591506132a0608088016131c8565b90509295509295509295565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b82811015612efc57603f198886030184526132ef858351613079565b945092850192908501906001016132d3565b60008060008060a0858703121561331757600080fd5b61332085612f09565b935061332e60208601612f09565b9250608085018681111561334157600080fd5b604086019250356001600160401b0381111561335c57600080fd5b61336887828801612f63565b91505092959194509250565b6000806040838503121561338757600080fd5b61339083612f09565b946020939093013593505050565b6000806000606084860312156133b357600080fd5b833592506133c360208501612f09565b91506133d160408501612f09565b90509250925092565b6000602082840312156133ec57600080fd5b61072a82612f09565b60006020828403121561340757600080fd5b81356001600160401b0381111561341d57600080fd5b61165f84828501612f63565b60006020828403121561343b57600080fd5b81356001600160401b0381111561345157600080fd5b820160e0818503121561346357600080fd5b9392505050565b60006020828403121561347c57600080fd5b5035919050565b60208152600061072a6020830184612dc9565b600181811c908216806134aa57607f821691505b6020821081036134ca57634e487b7160e01b600052602260045260246000fd5b50919050565b600082516134e2818460208701612cee565b9190910192915050565b60608152836060820152838560808301376000608085830101526000601f19601f8601168201608083820301602084015261352a608082018661303c565b915050821515604083015295945050505050565b60208082526021908201527f43616c6c6572206973206e6f7420746865206c656467657220636f6e747261636040820152601d60fa1b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b6000808335601e198436030181126135ac57600080fd5b8301803591506001600160401b038211156135c657600080fd5b6020019150368190038213156135db57600080fd5b9250929050565b8183823760009101908152919050565b600080835461360081613496565b60018281168015613618576001811461362d5761365c565b60ff198416875282151583028701945061365c565b8760005260208060002060005b858110156136535781548a82015290840190820161363a565b50505082870194505b50929695505050505050565b600060e0823603121561367a57600080fd5b613682612f3b565b8235815260208301356001600160401b03808211156136a057600080fd5b6136ac36838701612f63565b602084015260408501359150808211156136c557600080fd5b6136d136838701612f63565b604084015260608501359150808211156136ea57600080fd5b506136f736828601612f63565b6060830152506080830135608082015260a083013560a082015261371d60c08401612f09565b60c082015292915050565b601f82111561241657600081815260208120601f850160051c8101602086101561374f5750805b601f850160051c820191505b81811015611f8c5782815560010161375b565b6001600160401b0383111561378557613785612f25565b613799836137938354613496565b83613728565b6000601f8411600181146137cd57600085156137b55750838201355b600019600387901b1c1916600186901b1783556121b8565b600083815260209020601f19861690835b828110156137fe57868501358255602094850194600190920191016137de565b508682101561381b5760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b634e487b7160e01b600052601160045260246000fd5b6000600182016138555761385561382d565b5060010190565b81516001600160401b0381111561387557613875612f25565b613889816138838454613496565b84613728565b602080601f8311600181146138be57600084156138a65750858301515b600019600386901b1c1916600185901b178555611f8c565b600085815260208120601f198616915b828110156138ed578886015182559484019460019091019084016138ce565b508582101561390b5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6001600160a01b0392831681529116602082015260400190565b8082018082111561072d5761072d61382d565b8181038181111561072d5761072d61382d565b6001600160a01b038316815260406020820181905260009061165f90830184612d12565b6000600160ff1b82016139945761399461382d565b506000190190565b600086516139ae818460208b01612cee565b80830190508681528560208201526bffffffffffffffffffffffff198560601b16604082015283516139e7816054840160208801612cee565b01605401979650505050505050565b634e487b7160e01b600052603160045260246000fdfe526824944047da5b81071fb6349412005c5da81380b336103fbe5dd34556c776a2646970667358221220a8c8e8c22132ad67ede82e7cc9f311936807f8306c1a65973302b9fd40f1022d64736f6c63430008140033"; + +type FineTuneServingConstructorParams = + | [signer?: Signer] + | ConstructorParameters; + +const isSuperArgs = ( + xs: FineTuneServingConstructorParams +): xs is ConstructorParameters => xs.length > 1; + +export class FineTuneServing__factory extends ContractFactory { + constructor(...args: FineTuneServingConstructorParams) { + if (isSuperArgs(args)) { + super(...args); + } else { + super(_abi, _bytecode, args[0]); + } + } + + override getDeployTransaction( + overrides?: NonPayableOverrides & { from?: string } + ): Promise { + return super.getDeployTransaction(overrides || {}); + } + override deploy(overrides?: NonPayableOverrides & { from?: string }) { + return super.deploy(overrides || {}) as Promise< + FineTuneServing & { + deploymentTransaction(): ContractTransactionResponse; + } + >; + } + override connect(runner: ContractRunner | null): FineTuneServing__factory { + return super.connect(runner) as FineTuneServing__factory; + } + + static readonly bytecode = _bytecode; + static readonly abi = _abi; + static createInterface(): FineTuneServingInterface { + return new Interface(_abi) as FineTuneServingInterface; + } + static connect( + address: string, + runner?: ContractRunner | null + ): FineTuneServing { + return new Contract(address, _abi, runner) as unknown as FineTuneServing; + } +} diff --git a/src.ts/contract/finetune/factories/index.ts b/src.ts/contract/finetune/factories/index.ts new file mode 100644 index 0000000..0554453 --- /dev/null +++ b/src.ts/contract/finetune/factories/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { FineTuneServing__factory } from "./FineTuneServing__factory.js"; diff --git a/src.ts/contract/finetune/index.ts b/src.ts/contract/finetune/index.ts new file mode 100644 index 0000000..b9044fe --- /dev/null +++ b/src.ts/contract/finetune/index.ts @@ -0,0 +1,6 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { FineTuneServing } from "./FineTuneServing.js"; +export * as factories from "./factories/index.js"; +export { FineTuneServing__factory } from "./factories/FineTuneServing__factory.js"; diff --git a/src.ts/contract/index.ts b/src.ts/contract/index.ts index 4e30f34..244883d 100644 --- a/src.ts/contract/index.ts +++ b/src.ts/contract/index.ts @@ -1,3 +1,8 @@ export * from './contract' -export * from './serving' -export * from './serving/Serving' +export {ServiceStructOutput as FineTuneServiceStruct, QuotaStructOutput, AccountStructOutput as FineTuneAccountStruct} from './finetune/FineTuneServing' +export {FineTuneServing, FineTuneServing__factory } from './finetune' +export {ServiceStructOutput as InferenceServiceStruct, AccountStructOutput as InferenceAccountStruct} from './inference/InferenceServing' +export {InferenceServing, InferenceServing__factory } from './inference' +export {LedgerManager, LedgerStructOutput} from './ledger/LedgerManager' +export {LedgerManager__factory} from './ledger' + diff --git a/src.ts/contract/serving/Serving.ts b/src.ts/contract/inference/InferenceServing.ts similarity index 88% rename from src.ts/contract/serving/Serving.ts rename to src.ts/contract/inference/InferenceServing.ts index cfd7288..cf8c5bf 100644 --- a/src.ts/contract/serving/Serving.ts +++ b/src.ts/contract/inference/InferenceServing.ts @@ -121,9 +121,10 @@ export type VerifierInputStructOutput = [ segmentSize: bigint[]; }; -export interface ServingInterface extends Interface { +export interface InferenceServingInterface extends Interface { getFunction( nameOrSignature: + | "accountExists" | "addAccount" | "addOrUpdateService" | "batchVerifierAddress" @@ -135,12 +136,13 @@ export interface ServingInterface extends Interface { | "getService" | "initialize" | "initialized" + | "ledgerAddress" | "lockTime" | "owner" | "processRefund" | "removeService" | "renounceOwnership" - | "requestRefund" + | "requestRefundAll" | "settleFees" | "transferOwnership" | "updateBatchVerifierAddress" @@ -156,9 +158,13 @@ export interface ServingInterface extends Interface { | "ServiceUpdated" ): EventFragment; + encodeFunctionData( + functionFragment: "accountExists", + values: [AddressLike, AddressLike] + ): string; encodeFunctionData( functionFragment: "addAccount", - values: [AddressLike, [BigNumberish, BigNumberish], string] + values: [AddressLike, AddressLike, [BigNumberish, BigNumberish], string] ): string; encodeFunctionData( functionFragment: "addOrUpdateService", @@ -170,11 +176,11 @@ export interface ServingInterface extends Interface { ): string; encodeFunctionData( functionFragment: "deleteAccount", - values: [AddressLike] + values: [AddressLike, AddressLike] ): string; encodeFunctionData( functionFragment: "depositFund", - values: [AddressLike] + values: [AddressLike, AddressLike] ): string; encodeFunctionData( functionFragment: "getAccount", @@ -194,17 +200,21 @@ export interface ServingInterface extends Interface { ): string; encodeFunctionData( functionFragment: "initialize", - values: [BigNumberish, AddressLike, AddressLike] + values: [BigNumberish, AddressLike, AddressLike, AddressLike] ): string; encodeFunctionData( functionFragment: "initialized", values?: undefined ): string; + encodeFunctionData( + functionFragment: "ledgerAddress", + values?: undefined + ): string; encodeFunctionData(functionFragment: "lockTime", values?: undefined): string; encodeFunctionData(functionFragment: "owner", values?: undefined): string; encodeFunctionData( functionFragment: "processRefund", - values: [AddressLike, BigNumberish[]] + values: [AddressLike, AddressLike] ): string; encodeFunctionData( functionFragment: "removeService", @@ -215,8 +225,8 @@ export interface ServingInterface extends Interface { values?: undefined ): string; encodeFunctionData( - functionFragment: "requestRefund", - values: [AddressLike, BigNumberish] + functionFragment: "requestRefundAll", + values: [AddressLike, AddressLike] ): string; encodeFunctionData( functionFragment: "settleFees", @@ -235,6 +245,10 @@ export interface ServingInterface extends Interface { values: [BigNumberish] ): string; + decodeFunctionResult( + functionFragment: "accountExists", + data: BytesLike + ): Result; decodeFunctionResult(functionFragment: "addAccount", data: BytesLike): Result; decodeFunctionResult( functionFragment: "addOrUpdateService", @@ -267,6 +281,10 @@ export interface ServingInterface extends Interface { functionFragment: "initialized", data: BytesLike ): Result; + decodeFunctionResult( + functionFragment: "ledgerAddress", + data: BytesLike + ): Result; decodeFunctionResult(functionFragment: "lockTime", data: BytesLike): Result; decodeFunctionResult(functionFragment: "owner", data: BytesLike): Result; decodeFunctionResult( @@ -282,7 +300,7 @@ export interface ServingInterface extends Interface { data: BytesLike ): Result; decodeFunctionResult( - functionFragment: "requestRefund", + functionFragment: "requestRefundAll", data: BytesLike ): Result; decodeFunctionResult(functionFragment: "settleFees", data: BytesLike): Result; @@ -416,11 +434,11 @@ export namespace ServiceUpdatedEvent { export type LogDescription = TypedLogDescription; } -export interface Serving extends BaseContract { - connect(runner?: ContractRunner | null): Serving; +export interface InferenceServing extends BaseContract { + connect(runner?: ContractRunner | null): InferenceServing; waitForDeployment(): Promise; - interface: ServingInterface; + interface: InferenceServingInterface; queryFilter( event: TCEvent, @@ -459,8 +477,15 @@ export interface Serving extends BaseContract { event?: TCEvent ): Promise; + accountExists: TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [boolean], + "view" + >; + addAccount: TypedContractMethod< [ + user: AddressLike, provider: AddressLike, signer: [BigNumberish, BigNumberish], additionalInfo: string @@ -486,12 +511,16 @@ export interface Serving extends BaseContract { batchVerifierAddress: TypedContractMethod<[], [string], "view">; deleteAccount: TypedContractMethod< - [provider: AddressLike], + [user: AddressLike, provider: AddressLike], [void], "nonpayable" >; - depositFund: TypedContractMethod<[provider: AddressLike], [void], "payable">; + depositFund: TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [void], + "payable" + >; getAccount: TypedContractMethod< [user: AddressLike, provider: AddressLike], @@ -513,6 +542,7 @@ export interface Serving extends BaseContract { [ _locktime: BigNumberish, _batchVerifierAddress: AddressLike, + _ledgerAddress: AddressLike, owner: AddressLike ], [void], @@ -521,13 +551,21 @@ export interface Serving extends BaseContract { initialized: TypedContractMethod<[], [boolean], "view">; + ledgerAddress: TypedContractMethod<[], [string], "view">; + lockTime: TypedContractMethod<[], [bigint], "view">; owner: TypedContractMethod<[], [string], "view">; processRefund: TypedContractMethod< - [provider: AddressLike, indices: BigNumberish[]], - [void], + [user: AddressLike, provider: AddressLike], + [ + [bigint, bigint, bigint] & { + totalAmount: bigint; + balance: bigint; + pendingRefund: bigint; + } + ], "nonpayable" >; @@ -535,8 +573,8 @@ export interface Serving extends BaseContract { renounceOwnership: TypedContractMethod<[], [void], "nonpayable">; - requestRefund: TypedContractMethod< - [provider: AddressLike, amount: BigNumberish], + requestRefundAll: TypedContractMethod< + [user: AddressLike, provider: AddressLike], [void], "nonpayable" >; @@ -569,10 +607,18 @@ export interface Serving extends BaseContract { key: string | FunctionFragment ): T; + getFunction( + nameOrSignature: "accountExists" + ): TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [boolean], + "view" + >; getFunction( nameOrSignature: "addAccount" ): TypedContractMethod< [ + user: AddressLike, provider: AddressLike, signer: [BigNumberish, BigNumberish], additionalInfo: string @@ -600,10 +646,18 @@ export interface Serving extends BaseContract { ): TypedContractMethod<[], [string], "view">; getFunction( nameOrSignature: "deleteAccount" - ): TypedContractMethod<[provider: AddressLike], [void], "nonpayable">; + ): TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [void], + "nonpayable" + >; getFunction( nameOrSignature: "depositFund" - ): TypedContractMethod<[provider: AddressLike], [void], "payable">; + ): TypedContractMethod< + [user: AddressLike, provider: AddressLike], + [void], + "payable" + >; getFunction( nameOrSignature: "getAccount" ): TypedContractMethod< @@ -630,6 +684,7 @@ export interface Serving extends BaseContract { [ _locktime: BigNumberish, _batchVerifierAddress: AddressLike, + _ledgerAddress: AddressLike, owner: AddressLike ], [void], @@ -638,6 +693,9 @@ export interface Serving extends BaseContract { getFunction( nameOrSignature: "initialized" ): TypedContractMethod<[], [boolean], "view">; + getFunction( + nameOrSignature: "ledgerAddress" + ): TypedContractMethod<[], [string], "view">; getFunction( nameOrSignature: "lockTime" ): TypedContractMethod<[], [bigint], "view">; @@ -647,8 +705,14 @@ export interface Serving extends BaseContract { getFunction( nameOrSignature: "processRefund" ): TypedContractMethod< - [provider: AddressLike, indices: BigNumberish[]], - [void], + [user: AddressLike, provider: AddressLike], + [ + [bigint, bigint, bigint] & { + totalAmount: bigint; + balance: bigint; + pendingRefund: bigint; + } + ], "nonpayable" >; getFunction( @@ -658,9 +722,9 @@ export interface Serving extends BaseContract { nameOrSignature: "renounceOwnership" ): TypedContractMethod<[], [void], "nonpayable">; getFunction( - nameOrSignature: "requestRefund" + nameOrSignature: "requestRefundAll" ): TypedContractMethod< - [provider: AddressLike, amount: BigNumberish], + [user: AddressLike, provider: AddressLike], [void], "nonpayable" >; diff --git a/src.ts/contract/inference/common.ts b/src.ts/contract/inference/common.ts new file mode 100644 index 0000000..56b5f21 --- /dev/null +++ b/src.ts/contract/inference/common.ts @@ -0,0 +1,131 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + FunctionFragment, + Typed, + EventFragment, + ContractTransaction, + ContractTransactionResponse, + DeferredTopicFilter, + EventLog, + TransactionRequest, + LogDescription, +} from "ethers"; + +export interface TypedDeferredTopicFilter<_TCEvent extends TypedContractEvent> + extends DeferredTopicFilter {} + +export interface TypedContractEvent< + InputTuple extends Array = any, + OutputTuple extends Array = any, + OutputObject = any +> { + (...args: Partial): TypedDeferredTopicFilter< + TypedContractEvent + >; + name: string; + fragment: EventFragment; + getFragment(...args: Partial): EventFragment; +} + +type __TypechainAOutputTuple = T extends TypedContractEvent< + infer _U, + infer W +> + ? W + : never; +type __TypechainOutputObject = T extends TypedContractEvent< + infer _U, + infer _W, + infer V +> + ? V + : never; + +export interface TypedEventLog + extends Omit { + args: __TypechainAOutputTuple & __TypechainOutputObject; +} + +export interface TypedLogDescription + extends Omit { + args: __TypechainAOutputTuple & __TypechainOutputObject; +} + +export type TypedListener = ( + ...listenerArg: [ + ...__TypechainAOutputTuple, + TypedEventLog, + ...undefined[] + ] +) => void; + +export type MinEthersFactory = { + deploy(...a: ARGS[]): Promise; +}; + +export type GetContractTypeFromFactory = F extends MinEthersFactory< + infer C, + any +> + ? C + : never; +export type GetARGsTypeFromFactory = F extends MinEthersFactory + ? Parameters + : never; + +export type StateMutability = "nonpayable" | "payable" | "view"; + +export type BaseOverrides = Omit; +export type NonPayableOverrides = Omit< + BaseOverrides, + "value" | "blockTag" | "enableCcipRead" +>; +export type PayableOverrides = Omit< + BaseOverrides, + "blockTag" | "enableCcipRead" +>; +export type ViewOverrides = Omit; +export type Overrides = S extends "nonpayable" + ? NonPayableOverrides + : S extends "payable" + ? PayableOverrides + : ViewOverrides; + +export type PostfixOverrides, S extends StateMutability> = + | A + | [...A, Overrides]; +export type ContractMethodArgs< + A extends Array, + S extends StateMutability +> = PostfixOverrides<{ [I in keyof A]-?: A[I] | Typed }, S>; + +export type DefaultReturnType = R extends Array ? R[0] : R; + +// export interface ContractMethod = Array, R = any, D extends R | ContractTransactionResponse = R | ContractTransactionResponse> { +export interface TypedContractMethod< + A extends Array = Array, + R = any, + S extends StateMutability = "payable" +> { + (...args: ContractMethodArgs): S extends "view" + ? Promise> + : Promise; + + name: string; + + fragment: FunctionFragment; + + getFragment(...args: ContractMethodArgs): FunctionFragment; + + populateTransaction( + ...args: ContractMethodArgs + ): Promise; + staticCall( + ...args: ContractMethodArgs + ): Promise>; + send(...args: ContractMethodArgs): Promise; + estimateGas(...args: ContractMethodArgs): Promise; + staticCallResult(...args: ContractMethodArgs): Promise; +} diff --git a/src.ts/contract/inference/factories/InferenceServing__factory.ts b/src.ts/contract/inference/factories/InferenceServing__factory.ts new file mode 100644 index 0000000..7e7e1c5 --- /dev/null +++ b/src.ts/contract/inference/factories/InferenceServing__factory.ts @@ -0,0 +1,953 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { + Contract, + ContractFactory, + ContractTransactionResponse, + Interface, +} from "ethers"; +import type { Signer, ContractDeployTransaction, ContractRunner } from "ethers"; +import type { NonPayableOverrides } from "../common.js"; +import type { + InferenceServing, + InferenceServingInterface, +} from "../InferenceServing.js"; + +const _abi = [ + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "AccountExists", + type: "error", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "AccountNotExists", + type: "error", + }, + { + inputs: [ + { + internalType: "string", + name: "reason", + type: "string", + }, + ], + name: "InvalidProofInputs", + type: "error", + }, + { + inputs: [ + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "string", + name: "name", + type: "string", + }, + ], + name: "ServiceNotExist", + type: "error", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "user", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "provider", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "pendingRefund", + type: "uint256", + }, + ], + name: "BalanceUpdated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "previousOwner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "OwnershipTransferred", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "user", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "provider", + type: "address", + }, + { + indexed: true, + internalType: "uint256", + name: "index", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "timestamp", + type: "uint256", + }, + ], + name: "RefundRequested", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "service", + type: "address", + }, + { + indexed: true, + internalType: "string", + name: "name", + type: "string", + }, + ], + name: "ServiceRemoved", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "service", + type: "address", + }, + { + indexed: true, + internalType: "string", + name: "name", + type: "string", + }, + { + indexed: false, + internalType: "string", + name: "serviceType", + type: "string", + }, + { + indexed: false, + internalType: "string", + name: "url", + type: "string", + }, + { + indexed: false, + internalType: "uint256", + name: "inputPrice", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "outputPrice", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "updatedAt", + type: "uint256", + }, + { + indexed: false, + internalType: "string", + name: "model", + type: "string", + }, + { + indexed: false, + internalType: "string", + name: "verifiability", + type: "string", + }, + ], + name: "ServiceUpdated", + type: "event", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "accountExists", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "uint256[2]", + name: "signer", + type: "uint256[2]", + }, + { + internalType: "string", + name: "additionalInfo", + type: "string", + }, + ], + name: "addAccount", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "string", + name: "name", + type: "string", + }, + { + internalType: "string", + name: "serviceType", + type: "string", + }, + { + internalType: "string", + name: "url", + type: "string", + }, + { + internalType: "string", + name: "model", + type: "string", + }, + { + internalType: "string", + name: "verifiability", + type: "string", + }, + { + internalType: "uint256", + name: "inputPrice", + type: "uint256", + }, + { + internalType: "uint256", + name: "outputPrice", + type: "uint256", + }, + ], + name: "addOrUpdateService", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "batchVerifierAddress", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "deleteAccount", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "depositFund", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "getAccount", + outputs: [ + { + components: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "uint256", + name: "nonce", + type: "uint256", + }, + { + internalType: "uint256", + name: "balance", + type: "uint256", + }, + { + internalType: "uint256", + name: "pendingRefund", + type: "uint256", + }, + { + internalType: "uint256[2]", + name: "signer", + type: "uint256[2]", + }, + { + components: [ + { + internalType: "uint256", + name: "index", + type: "uint256", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + internalType: "uint256", + name: "createdAt", + type: "uint256", + }, + { + internalType: "bool", + name: "processed", + type: "bool", + }, + ], + internalType: "struct Refund[]", + name: "refunds", + type: "tuple[]", + }, + { + internalType: "string", + name: "additionalInfo", + type: "string", + }, + ], + internalType: "struct Account", + name: "", + type: "tuple", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getAllAccounts", + outputs: [ + { + components: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "uint256", + name: "nonce", + type: "uint256", + }, + { + internalType: "uint256", + name: "balance", + type: "uint256", + }, + { + internalType: "uint256", + name: "pendingRefund", + type: "uint256", + }, + { + internalType: "uint256[2]", + name: "signer", + type: "uint256[2]", + }, + { + components: [ + { + internalType: "uint256", + name: "index", + type: "uint256", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + internalType: "uint256", + name: "createdAt", + type: "uint256", + }, + { + internalType: "bool", + name: "processed", + type: "bool", + }, + ], + internalType: "struct Refund[]", + name: "refunds", + type: "tuple[]", + }, + { + internalType: "string", + name: "additionalInfo", + type: "string", + }, + ], + internalType: "struct Account[]", + name: "", + type: "tuple[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getAllServices", + outputs: [ + { + components: [ + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "string", + name: "name", + type: "string", + }, + { + internalType: "string", + name: "serviceType", + type: "string", + }, + { + internalType: "string", + name: "url", + type: "string", + }, + { + internalType: "uint256", + name: "inputPrice", + type: "uint256", + }, + { + internalType: "uint256", + name: "outputPrice", + type: "uint256", + }, + { + internalType: "uint256", + name: "updatedAt", + type: "uint256", + }, + { + internalType: "string", + name: "model", + type: "string", + }, + { + internalType: "string", + name: "verifiability", + type: "string", + }, + ], + internalType: "struct Service[]", + name: "services", + type: "tuple[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "string", + name: "name", + type: "string", + }, + ], + name: "getService", + outputs: [ + { + components: [ + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "string", + name: "name", + type: "string", + }, + { + internalType: "string", + name: "serviceType", + type: "string", + }, + { + internalType: "string", + name: "url", + type: "string", + }, + { + internalType: "uint256", + name: "inputPrice", + type: "uint256", + }, + { + internalType: "uint256", + name: "outputPrice", + type: "uint256", + }, + { + internalType: "uint256", + name: "updatedAt", + type: "uint256", + }, + { + internalType: "string", + name: "model", + type: "string", + }, + { + internalType: "string", + name: "verifiability", + type: "string", + }, + ], + internalType: "struct Service", + name: "service", + type: "tuple", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_locktime", + type: "uint256", + }, + { + internalType: "address", + name: "_batchVerifierAddress", + type: "address", + }, + { + internalType: "address", + name: "_ledgerAddress", + type: "address", + }, + { + internalType: "address", + name: "owner", + type: "address", + }, + ], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "initialized", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "ledgerAddress", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "lockTime", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "owner", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "processRefund", + outputs: [ + { + internalType: "uint256", + name: "totalAmount", + type: "uint256", + }, + { + internalType: "uint256", + name: "balance", + type: "uint256", + }, + { + internalType: "uint256", + name: "pendingRefund", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "string", + name: "name", + type: "string", + }, + ], + name: "removeService", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "renounceOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "address", + name: "provider", + type: "address", + }, + ], + name: "requestRefundAll", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + components: [ + { + internalType: "uint256[]", + name: "inProof", + type: "uint256[]", + }, + { + internalType: "uint256[]", + name: "proofInputs", + type: "uint256[]", + }, + { + internalType: "uint256", + name: "numChunks", + type: "uint256", + }, + { + internalType: "uint256[]", + name: "segmentSize", + type: "uint256[]", + }, + ], + internalType: "struct VerifierInput", + name: "verifierInput", + type: "tuple", + }, + ], + name: "settleFees", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_batchVerifierAddress", + type: "address", + }, + ], + name: "updateBatchVerifierAddress", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_locktime", + type: "uint256", + }, + ], + name: "updateLockTime", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, +] as const; + +const _bytecode = + "0x60806040523480156200001157600080fd5b506200001d3362000023565b62000073565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6133c280620000836000396000f3fe6080604052600436106101405760003560e01c80636c79158d116100b6578063972167251161006f57806397216725146103a2578063d1d20056146103c2578063f2fde38b146103e2578063f51acaea14610402578063fbfa4e1114610422578063fd5908471461044257600080fd5b80636c79158d146102ef578063715018a61461030f578063746e78d714610324578063754d1d541461034457806378c00436146103645780638da5cb5b1461038457600080fd5b806321fe0f301161010857806321fe0f3014610212578063371c22c5146102345780633f54d9731461026c5780634bc3aff4146102815780634e3c4f22146102945780636341b2d1146102cf57600080fd5b806308e93d0a146101455780630d668087146101705780630e61d15814610194578063147500e3146101c1578063158ef93e146101f1575b600080fd5b34801561015157600080fd5b5061015a61046f565b6040516101679190612a05565b60405180910390f35b34801561017c57600080fd5b5061018660015481565b604051908152602001610167565b3480156101a057600080fd5b506101b46101af366004612b26565b610480565b6040516101679190612c2e565b3480156101cd57600080fd5b506101e16101dc366004612c41565b6107b5565b6040519015158152602001610167565b3480156101fd57600080fd5b506000546101e190600160a01b900460ff1681565b34801561021e57600080fd5b506102276107cc565b6040516101679190612c74565b34801561024057600080fd5b50600254610254906001600160a01b031681565b6040516001600160a01b039091168152602001610167565b61027f61027a366004612c41565b6107d8565b005b61027f61028f366004612cc9565b610869565b3480156102a057600080fd5b506102b46102af366004612c41565b6108f5565b60408051938452602084019290925290820152606001610167565b3480156102db57600080fd5b5061027f6102ea366004612d86565b6109ba565b3480156102fb57600080fd5b5061027f61030a366004612c41565b610ae5565b34801561031b57600080fd5b5061027f610b1f565b34801561033057600080fd5b5061027f61033f366004612e7b565b610b33565b34801561035057600080fd5b5061027f61035f366004612e96565b610b67565b34801561037057600080fd5b5061027f61037f366004612ee3565b610c2d565b34801561039057600080fd5b506000546001600160a01b0316610254565b3480156103ae57600080fd5b5061027f6103bd366004612c41565b611245565b3480156103ce57600080fd5b50600354610254906001600160a01b031681565b3480156103ee57600080fd5b5061027f6103fd366004612e7b565b61127b565b34801561040e57600080fd5b5061027f61041d366004612f25565b6112f4565b34801561042e57600080fd5b5061027f61043d366004612f5a565b611343565b34801561044e57600080fd5b5061046261045d366004612c41565b611350565b6040516101679190612f73565b606061047b6005611473565b905090565b610488612701565b610494600884846116b4565b60408051610120810190915281546001600160a01b031681526001820180549192916020840191906104c590612f86565b80601f01602080910402602001604051908101604052809291908181526020018280546104f190612f86565b801561053e5780601f106105135761010080835404028352916020019161053e565b820191906000526020600020905b81548152906001019060200180831161052157829003601f168201915b5050505050815260200160028201805461055790612f86565b80601f016020809104026020016040519081016040528092919081815260200182805461058390612f86565b80156105d05780601f106105a5576101008083540402835291602001916105d0565b820191906000526020600020905b8154815290600101906020018083116105b357829003601f168201915b505050505081526020016003820180546105e990612f86565b80601f016020809104026020016040519081016040528092919081815260200182805461061590612f86565b80156106625780601f1061063757610100808354040283529160200191610662565b820191906000526020600020905b81548152906001019060200180831161064557829003601f168201915b5050505050815260200160048201548152602001600582015481526020016006820154815260200160078201805461069990612f86565b80601f01602080910402602001604051908101604052809291908181526020018280546106c590612f86565b80156107125780601f106106e757610100808354040283529160200191610712565b820191906000526020600020905b8154815290600101906020018083116106f557829003601f168201915b5050505050815260200160088201805461072b90612f86565b80601f016020809104026020016040519081016040528092919081815260200182805461075790612f86565b80156107a45780601f10610779576101008083540402835291602001916107a4565b820191906000526020600020905b81548152906001019060200180831161078757829003601f168201915b505050505081525050905092915050565b60006107c3600584846116c9565b90505b92915050565b606061047b60086116de565b6003546001600160a01b0316331461080b5760405162461bcd60e51b815260040161080290612fc0565b60405180910390fd5b60008061081b6005858534611a9e565b91509150826001600160a01b0316846001600160a01b031660008051602061336d833981519152848460405161085b929190918252602082015260400190565b60405180910390a350505050565b6003546001600160a01b031633146108935760405162461bcd60e51b815260040161080290612fc0565b6000806108a560058787873488611b2a565b91509150846001600160a01b0316866001600160a01b031660008051602061336d83398151915284846040516108e5929190918252602082015260400190565b60405180910390a3505050505050565b600354600090819081906001600160a01b031633146109265760405162461bcd60e51b815260040161080290612fc0565b6001546109399060059087908790611b95565b6040519295509093509150339084156108fc029085906000818181858888f1935050505015801561096e573d6000803e3d6000fd5b50836001600160a01b0316856001600160a01b031660008051602061336d83398151915284846040516109ab929190918252602082015260400190565b60405180910390a39250925092565b610a70338b8b8b8b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8f018190048102820181019092528d815292508d91508c908190840183828082843760009201919091525050604080516020601f8e018190048102820181019092528c815292508c91508b9081908401838280828437600092019190915250600898979695949392508b91508a9050611cd0565b89604051610a7e9190613001565b6040518091039020336001600160a01b03167f95e1ef74a36b7d6ac766d338a4468c685d593739c3b7dc39e2aa5921a1e139328b8b8b8787428e8e8e8e604051610ad19a99989796959493929190613046565b60405180910390a350505050505050505050565b6003546001600160a01b03163314610b0f5760405162461bcd60e51b815260040161080290612fc0565b610b1b60058383611dc2565b5050565b610b27611e83565b610b316000611edd565b565b610b3b611e83565b600280546001600160a01b039092166001600160a01b0319928316811790915560048054909216179055565b600054600160a01b900460ff1615610bcc5760405162461bcd60e51b815260206004820152602260248201527f496e697469616c697a61626c653a20616c726561647920696e697469616c697a604482015261195960f21b6064820152608401610802565b6000805460ff60a01b1916600160a01b179055610be881611edd565b50600192909255600280546001600160a01b039283166001600160a01b0319918216811790925560038054949093169381169390931790915560048054909216179055565b6004546000906001600160a01b031663ad12259a610c4b84806130b9565b610c5860208701876130b9565b87604001356040518663ffffffff1660e01b8152600401610c7d959493929190613135565b602060405180830381865afa158015610c9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cbe919061316f565b905080610d0e5760405163885e287960e01b815260206004820152601f60248201527f5a4b20736574746c656d656e742076616c69646174696f6e206661696c6564006044820152606401610802565b6000610d1d60208401846130b9565b808060200260200160405190810160405280939291908181526020018383602002808284376000920182905250939450339250839150505b610d6260608701876130b9565b90508110156111cf576000610d7a60608801886130b9565b83818110610d8a57610d8a613191565b90506020020135905060008185610da191906131bd565b9050600080878781518110610db857610db8613191565b60200260200101519050600088886002610dd291906131bd565b81518110610de257610de2613191565b60200260200101519050600089896003610dfc91906131bd565b81518110610e0c57610e0c613191565b602002602001015190506000610e2e84336005611f2d9092919063ffffffff16565b90508a610e3c8b60056131bd565b81518110610e4c57610e4c613191565b602002602001015181600501600060028110610e6a57610e6a613191565b0154141580610eb357508a610e808b60066131bd565b81518110610e9057610e90613191565b602002602001015181600501600160028110610eae57610eae613191565b015414155b15610f015760405163885e287960e01b815260206004820152601760248201527f7369676e6572206b657920697320696e636f72726563740000000000000000006044820152606401610802565b8281600201541115610f565760405163885e287960e01b815260206004820152601a60248201527f696e697469616c206e6f6e636520697320696e636f72726563740000000000006044820152606401610802565b895b868110156111585760008c8281518110610f7457610f74613191565b6020026020010151905060008d836001610f8e91906131bd565b81518110610f9e57610f9e613191565b602002602001015190508d836003610fb691906131bd565b81518110610fc657610fc6613191565b6020026020010151945060008e846004610fe091906131bd565b81518110610ff057610ff0613191565b6020026020010151905060008a85600961100a91906131bd565b1061101657600061103b565b8f6110228660096131bd565b8151811061103257611032613191565b60200260200101515b9050801580159061104c5750808710155b1561108d5760405163885e287960e01b815260206004820152601060248201526f1b9bdb98d9481bdd995c9b185c1c195960821b6044820152606401610802565b888414158061109c57508d8314155b15611134578884036110e3576040518060400160405280601d81526020017f70726f7669646572206164647265737320697320696e636f727265637400000081525061111a565b6040518060400160405280601981526020017f75736572206164647265737320697320696e636f7272656374000000000000008152505b60405163885e287960e01b815260040161080291906131d0565b61113e828b6131bd565b99505050505060078161115191906131bd565b9050610f58565b5084816003015410156111a55760405163885e287960e01b8152602060048201526014602482015273696e73756666696369656e742062616c616e636560601b6044820152606401610802565b6111af8186611f3a565b60020155509195508392506111c791508290506131e3565b915050610d55565b508251821461123e5760405163885e287960e01b815260206004820152603460248201527f6172726179207365676d656e7453697a652073756d206d69736d617463686573604482015273040e0eac4d8d2c640d2dce0eae840d8cadccee8d60631b6064820152608401610802565b5050505050565b6003546001600160a01b0316331461126f5760405162461bcd60e51b815260040161080290612fc0565b610b1b60058383612143565b611283611e83565b6001600160a01b0381166112e85760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610802565b6112f181611edd565b50565b61130060083383612209565b8060405161130e9190613001565b6040519081900381209033907f68026479739e3662c0651578523384b94455e79bfb701ce111a3164591ceba7390600090a350565b61134b611e83565b600155565b611358612756565b61136460058484611f2d565b604080516101008101825282546001600160a01b039081168252600184015416602082015260028084015482840152600384015460608301526004840154608083015282518084019384905291939260a085019291600585019182845b8154815260200190600101908083116113c1575050505050815260200160078201805480602002602001604051908101604052809291908181526020016000905b8282101561145b576000848152602090819020604080516080810182526004860290920180548352600180820154848601526002820154928401929092526003015460ff16151560608301529083529092019101611402565b50505050815260200160088201805461072b90612f86565b606060006114808361224c565b90508067ffffffffffffffff81111561149b5761149b612a83565b6040519080825280602002602001820160405280156114d457816020015b6114c1612756565b8152602001906001900390816114b95790505b50915060005b818110156116ad576114ec8482612257565b604080516101008101825282546001600160a01b039081168252600184015416602082015260028084015482840152600384015460608301526004840154608083015282518084019384905291939260a085019291600585019182845b815481526020019060010190808311611549575050505050815260200160078201805480602002602001604051908101604052809291908181526020016000905b828210156115e3576000848152602090819020604080516080810182526004860290920180548352600180820154848601526002820154928401929092526003015460ff1615156060830152908352909201910161158a565b5050505081526020016008820180546115fb90612f86565b80601f016020809104026020016040519081016040528092919081815260200182805461162790612f86565b80156116745780601f1061164957610100808354040283529160200191611674565b820191906000526020600020905b81548152906001019060200180831161165757829003601f168201915b50505050508152505083828151811061168f5761168f613191565b602002602001018190525080806116a5906131e3565b9150506114da565b5050919050565b60006116c184848461227d565b949350505050565b60006116c1846116d985856122d1565b612313565b606060006116eb8361224c565b90508067ffffffffffffffff81111561170657611706612a83565b60405190808252806020026020018201604052801561173f57816020015b61172c612701565b8152602001906001900390816117245790505b50915060005b818110156116ad576117578482612257565b60408051610120810190915281546001600160a01b0316815260018201805491929160208401919061178890612f86565b80601f01602080910402602001604051908101604052809291908181526020018280546117b490612f86565b80156118015780601f106117d657610100808354040283529160200191611801565b820191906000526020600020905b8154815290600101906020018083116117e457829003601f168201915b5050505050815260200160028201805461181a90612f86565b80601f016020809104026020016040519081016040528092919081815260200182805461184690612f86565b80156118935780601f1061186857610100808354040283529160200191611893565b820191906000526020600020905b81548152906001019060200180831161187657829003601f168201915b505050505081526020016003820180546118ac90612f86565b80601f01602080910402602001604051908101604052809291908181526020018280546118d890612f86565b80156119255780601f106118fa57610100808354040283529160200191611925565b820191906000526020600020905b81548152906001019060200180831161190857829003601f168201915b5050505050815260200160048201548152602001600582015481526020016006820154815260200160078201805461195c90612f86565b80601f016020809104026020016040519081016040528092919081815260200182805461198890612f86565b80156119d55780601f106119aa576101008083540402835291602001916119d5565b820191906000526020600020905b8154815290600101906020018083116119b857829003601f168201915b505050505081526020016008820180546119ee90612f86565b80601f0160208091040260200160405190810160405280929190818152602001828054611a1a90612f86565b8015611a675780601f10611a3c57610100808354040283529160200191611a67565b820191906000526020600020905b815481529060010190602001808311611a4a57829003601f168201915b505050505081525050838281518110611a8257611a82613191565b602002602001018190525080611a97906131e3565b9050611745565b6000806000611aad86866122d1565b9050611ab98782612313565b611ae95760405163023280eb60e21b81526001600160a01b03808816600483015286166024820152604401610802565b6000611af688888861231f565b905084816003016000828254611b0c91906131bd565b90915550506003810154600490910154909890975095505050505050565b6000806000611b3988886122d1565b9050611b458982612313565b15611b7657604051632cf0675960e21b81526001600160a01b03808a16600483015288166024820152604401610802565b611b8589828a8a8a8a8a612379565b5092976000975095505050505050565b600080600080611ba688888861231f565b90506000935060005b6007820154811015611cb6576000826007018281548110611bd257611bd2613191565b60009182526020909120600490910201600381015490915060ff1615611bf85750611ca4565b868160020154611c0891906131bd565b421015611c155750611ca4565b8060010154836003016000828254611c2d91906131fc565b90915550506001810154600484018054600090611c4b9084906131fc565b909155505060078301805483908110611c6657611c66613191565b60009182526020822060049091020181815560018082018390556002820192909255600301805460ff19169055810154611ca090876131bd565b9550505b80611cae816131e3565b915050611baf565b508060030154925080600401549150509450945094915050565b6000611cdc89896123e9565b9050611ce88a82612313565b611d4657611d3f8a826040518061012001604052808d6001600160a01b031681526020018c81526020018b81526020018a8152602001878152602001868152602001428152602001898152602001888152506123fe565b5050611db7565b6000611d538b8b8b61227d565b905060018101611d638a82613255565b5060028101611d728982613255565b50600481018490556005810183905560038101611d8f8882613255565b5042600682015560078101611da48782613255565b5060088101611db38682613255565b5050505b505050505050505050565b6000611dcf84848461231f565b9050600081600401548260030154611de791906131fc565b905080600003611df8575050505050565b6040805160808101825260078401805480835260208084018681524295850195865260006060860181815260018086018755958252928120955160049485029096019586559051938501939093559351600284015592516003909201805460ff1916921515929092179091559083018054839290611e779084906131bd565b90915550505050505050565b6000546001600160a01b03163314610b315760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610802565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006116c184848461231f565b81600401548260030154611f4e91906131fc565b8111156120b357600082600401548360030154611f6b91906131fc565b611f7590836131fc565b90508083600401541015611fda5760405163885e287960e01b815260206004820152602560248201527f696e73756666696369656e742062616c616e636520696e2070656e64696e675260448201526419599d5b9960da1b6064820152608401610802565b80836004016000828254611fee91906131fc565b90915550506007830154600090612007906001906131fc565b90505b600081126120b057600084600701828154811061202957612029613191565b60009182526020909120600490910201600381015490915060ff161561204f575061209e565b8281600101541161207057600181015461206990846131fc565b925061208e565b8281600101600082825461208491906131fc565b9091555060009350505b8260000361209c57506120b0565b505b806120a881613315565b91505061200a565b50505b808260030160008282546120c791906131fc565b909155505081546003830154600484015460405133936001600160a01b03169260008051602061336d8339815191529261210992918252602082015260400190565b60405180910390a3604051339082156108fc029083906000818181858888f1935050505015801561213e573d6000803e3d6000fd5b505050565b600061214f83836122d1565b905061215b8482612313565b61218b5760405163023280eb60e21b81526001600160a01b03808516600483015283166024820152604401610802565b61219584826124c4565b50600081815260028086016020526040822080546001600160a01b03199081168255600182018054909116905590810182905560038101829055600481018290556005810182905560068101829055906121f36007830160006127b3565b6122016008830160006127d4565b505050505050565b600061221583836123e9565b90506122218482612313565b612242578282604051636e41f4cf60e11b8152600401610802929190613332565b61123e84826124d0565b60006107c68261255b565b6000806122648484612565565b6000908152600285016020526040902091505092915050565b60008061228a84846123e9565b600081815260028701602052604090209091506122a78683612313565b6122c8578484604051636e41f4cf60e11b8152600401610802929190613332565b95945050505050565b604080516001600160a01b0380851660208301528316918101919091526000906060015b60405160208183030381529060405280519060200120905092915050565b60006107c38383612571565b60008061232c84846122d1565b600081815260028701602052604090209091506123498683612313565b6122c85760405163023280eb60e21b81526001600160a01b03808716600483015285166024820152604401610802565b6000868152600280890160205260409091206003810184905580546001600160a01b038089166001600160a01b031992831617835560018301805491891691909216179055906123cf906005830190869061280e565b50600881016123de8382613255565b50611db78888612589565b600082826040516020016122f5929190613332565b600082815260028401602090815260408220835181546001600160a01b0319166001600160a01b039091161781559083015183919060018201906124429082613255565b50604082015160028201906124579082613255565b506060820151600382019061246c9082613255565b506080820151600482015560a0820151600582015560c0820151600682015560e0820151600782019061249f9082613255565b5061010082015160088201906124b59082613255565b506116c1915085905084612589565b60006107c38383612595565b6000818152600283016020526040812080546001600160a01b0319168155816124fc60018301826127d4565b61250a6002830160006127d4565b6125186003830160006127d4565b60048201600090556005820160009055600682016000905560078201600061254091906127d4565b61254e6008830160006127d4565b506107c3905083836124c4565b60006107c6825490565b60006107c38383612688565b600081815260018301602052604081205415156107c3565b60006107c383836126b2565b6000818152600183016020526040812054801561267e5760006125b96001836131fc565b85549091506000906125cd906001906131fc565b90508181146126325760008660000182815481106125ed576125ed613191565b906000526020600020015490508087600001848154811061261057612610613191565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061264357612643613356565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506107c6565b60009150506107c6565b600082600001828154811061269f5761269f613191565b9060005260206000200154905092915050565b60008181526001830160205260408120546126f9575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556107c6565b5060006107c6565b60405180610120016040528060006001600160a01b0316815260200160608152602001606081526020016060815260200160008152602001600081526020016000815260200160608152602001606081525090565b60405180610100016040528060006001600160a01b0316815260200160006001600160a01b0316815260200160008152602001600081526020016000815260200161279f61284c565b815260200160608152602001606081525090565b50805460008255600402906000526020600020908101906112f1919061286a565b5080546127e090612f86565b6000825580601f106127f0575050565b601f0160209004906000526020600020908101906112f19190612898565b826002810192821561283c579160200282015b8281111561283c578235825591602001919060010190612821565b50612848929150612898565b5090565b60405180604001604052806002906020820280368337509192915050565b5b8082111561284857600080825560018201819055600282015560038101805460ff1916905560040161286b565b5b808211156128485760008155600101612899565b8060005b60028110156128d05781518452602093840193909101906001016128b1565b50505050565b600081518084526020808501945080840160005b8381101561292857815180518852838101518489015260408082015190890152606090810151151590880152608090960195908201906001016128ea565b509495945050505050565b60005b8381101561294e578181015183820152602001612936565b50506000910152565b6000815180845261296f816020860160208601612933565b601f01601f19169290920160200192915050565b600061012060018060a01b038084511685528060208501511660208601525060408301516040850152606083015160608501526080830151608085015260a08301516129d260a08601826128ad565b5060c08301518160e08601526129ea828601826128d6565b91505060e08301518482036101008601526122c88282612957565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b82811015612a5a57603f19888603018452612a48858351612983565b94509285019290850190600101612a2c565b5092979650505050505050565b80356001600160a01b0381168114612a7e57600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b600082601f830112612aaa57600080fd5b813567ffffffffffffffff80821115612ac557612ac5612a83565b604051601f8301601f19908116603f01168101908282118183101715612aed57612aed612a83565b81604052838152866020858801011115612b0657600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008060408385031215612b3957600080fd5b612b4283612a67565b9150602083013567ffffffffffffffff811115612b5e57600080fd5b612b6a85828601612a99565b9150509250929050565b80516001600160a01b0316825260006101206020830151816020860152612b9d82860182612957565b91505060408301518482036040860152612bb78282612957565b91505060608301518482036060860152612bd18282612957565b9150506080830151608085015260a083015160a085015260c083015160c085015260e083015184820360e0860152612c098282612957565b9150506101008084015185830382870152612c248382612957565b9695505050505050565b6020815260006107c36020830184612b74565b60008060408385031215612c5457600080fd5b612c5d83612a67565b9150612c6b60208401612a67565b90509250929050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b82811015612a5a57603f19888603018452612cb7858351612b74565b94509285019290850190600101612c9b565b60008060008060a08587031215612cdf57600080fd5b612ce885612a67565b9350612cf660208601612a67565b92506080850186811115612d0957600080fd5b6040860192503567ffffffffffffffff811115612d2557600080fd5b612d3187828801612a99565b91505092959194509250565b60008083601f840112612d4f57600080fd5b50813567ffffffffffffffff811115612d6757600080fd5b602083019150836020828501011115612d7f57600080fd5b9250929050565b60008060008060008060008060008060e08b8d031215612da557600080fd5b8a3567ffffffffffffffff80821115612dbd57600080fd5b612dc98e838f01612a99565b9b5060208d0135915080821115612ddf57600080fd5b612deb8e838f01612a99565b9a5060408d0135915080821115612e0157600080fd5b612e0d8e838f01612d3d565b909a50985060608d0135915080821115612e2657600080fd5b612e328e838f01612d3d565b909850965060808d0135915080821115612e4b57600080fd5b50612e588d828e01612d3d565b9b9e9a9d50989b979a969995989760a08101359660c09091013595509350505050565b600060208284031215612e8d57600080fd5b6107c382612a67565b60008060008060808587031215612eac57600080fd5b84359350612ebc60208601612a67565b9250612eca60408601612a67565b9150612ed860608601612a67565b905092959194509250565b600060208284031215612ef557600080fd5b813567ffffffffffffffff811115612f0c57600080fd5b820160808185031215612f1e57600080fd5b9392505050565b600060208284031215612f3757600080fd5b813567ffffffffffffffff811115612f4e57600080fd5b6116c184828501612a99565b600060208284031215612f6c57600080fd5b5035919050565b6020815260006107c36020830184612983565b600181811c90821680612f9a57607f821691505b602082108103612fba57634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526021908201527f43616c6c6572206973206e6f7420746865206c656467657220636f6e747261636040820152601d60fa1b606082015260800190565b60008251613013818460208701612933565b9190910192915050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b60e08152600061305960e083018d612957565b828103602084015261306c818c8e61301d565b905089604084015288606084015287608084015282810360a084015261309381878961301d565b905082810360c08401526130a881858761301d565b9d9c50505050505050505050505050565b6000808335601e198436030181126130d057600080fd5b83018035915067ffffffffffffffff8211156130eb57600080fd5b6020019150600581901b3603821315612d7f57600080fd5b81835260006001600160fb1b0383111561311c57600080fd5b8260051b80836020870137939093016020019392505050565b606081526000613149606083018789613103565b828103602084015261315c818688613103565b9150508260408301529695505050505050565b60006020828403121561318157600080fd5b81518015158114612f1e57600080fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b808201808211156107c6576107c66131a7565b6020815260006107c36020830184612957565b6000600182016131f5576131f56131a7565b5060010190565b818103818111156107c6576107c66131a7565b601f82111561213e57600081815260208120601f850160051c810160208610156132365750805b601f850160051c820191505b8181101561220157828155600101613242565b815167ffffffffffffffff81111561326f5761326f612a83565b6132838161327d8454612f86565b8461320f565b602080601f8311600181146132b857600084156132a05750858301515b600019600386901b1c1916600185901b178555612201565b600085815260208120601f198616915b828110156132e7578886015182559484019460019091019084016132c8565b50858210156133055787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6000600160ff1b820161332a5761332a6131a7565b506000190190565b6001600160a01b03831681526040602082018190526000906116c190830184612957565b634e487b7160e01b600052603160045260246000fdfe526824944047da5b81071fb6349412005c5da81380b336103fbe5dd34556c776a2646970667358221220d8caceaf6e7037cb01c96e0bec4bc4033d1623efe493ed8f55533e7818b5f9e264736f6c63430008140033"; + +type InferenceServingConstructorParams = + | [signer?: Signer] + | ConstructorParameters; + +const isSuperArgs = ( + xs: InferenceServingConstructorParams +): xs is ConstructorParameters => xs.length > 1; + +export class InferenceServing__factory extends ContractFactory { + constructor(...args: InferenceServingConstructorParams) { + if (isSuperArgs(args)) { + super(...args); + } else { + super(_abi, _bytecode, args[0]); + } + } + + override getDeployTransaction( + overrides?: NonPayableOverrides & { from?: string } + ): Promise { + return super.getDeployTransaction(overrides || {}); + } + override deploy(overrides?: NonPayableOverrides & { from?: string }) { + return super.deploy(overrides || {}) as Promise< + InferenceServing & { + deploymentTransaction(): ContractTransactionResponse; + } + >; + } + override connect(runner: ContractRunner | null): InferenceServing__factory { + return super.connect(runner) as InferenceServing__factory; + } + + static readonly bytecode = _bytecode; + static readonly abi = _abi; + static createInterface(): InferenceServingInterface { + return new Interface(_abi) as InferenceServingInterface; + } + static connect( + address: string, + runner?: ContractRunner | null + ): InferenceServing { + return new Contract(address, _abi, runner) as unknown as InferenceServing; + } +} diff --git a/src.ts/contract/inference/factories/index.ts b/src.ts/contract/inference/factories/index.ts new file mode 100644 index 0000000..a5bf42b --- /dev/null +++ b/src.ts/contract/inference/factories/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { InferenceServing__factory } from "./InferenceServing__factory.js"; diff --git a/src.ts/contract/inference/index.ts b/src.ts/contract/inference/index.ts new file mode 100644 index 0000000..68a5ee7 --- /dev/null +++ b/src.ts/contract/inference/index.ts @@ -0,0 +1,6 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { InferenceServing } from "./InferenceServing.js"; +export * as factories from "./factories/index.js"; +export { InferenceServing__factory } from "./factories/InferenceServing__factory.js"; diff --git a/src.ts/contract/ledger/LedgerManager.ts b/src.ts/contract/ledger/LedgerManager.ts new file mode 100644 index 0000000..325e477 --- /dev/null +++ b/src.ts/contract/ledger/LedgerManager.ts @@ -0,0 +1,365 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumberish, + BytesLike, + FunctionFragment, + Result, + Interface, + EventFragment, + AddressLike, + ContractRunner, + ContractMethod, + Listener, +} from "ethers"; +import type { + TypedContractEvent, + TypedDeferredTopicFilter, + TypedEventLog, + TypedLogDescription, + TypedListener, + TypedContractMethod, +} from "./common.js"; + +export type LedgerStruct = { + user: AddressLike; + availableBalance: BigNumberish; + totalBalance: BigNumberish; + signer: [BigNumberish, BigNumberish]; + additionalInfo: string; +}; + +export type LedgerStructOutput = [ + user: string, + availableBalance: bigint, + totalBalance: bigint, + signer: [bigint, bigint], + additionalInfo: string +] & { + user: string; + availableBalance: bigint; + totalBalance: bigint; + signer: [bigint, bigint]; + additionalInfo: string; +}; + +export interface LedgerManagerInterface extends Interface { + getFunction( + nameOrSignature: + | "addLedger" + | "depositFund" + | "fineTuneAddress" + | "getAllLedgers" + | "getLedger" + | "inferenceAddress" + | "initialize" + | "initialized" + | "owner" + | "refund" + | "renounceOwnership" + | "retrieveFund" + | "transferFund" + | "transferOwnership" + ): FunctionFragment; + + getEvent(nameOrSignatureOrTopic: "OwnershipTransferred"): EventFragment; + + encodeFunctionData( + functionFragment: "addLedger", + values: [[BigNumberish, BigNumberish], string] + ): string; + encodeFunctionData( + functionFragment: "depositFund", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "fineTuneAddress", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getAllLedgers", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getLedger", + values: [AddressLike] + ): string; + encodeFunctionData( + functionFragment: "inferenceAddress", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "initialize", + values: [AddressLike, AddressLike, AddressLike] + ): string; + encodeFunctionData( + functionFragment: "initialized", + values?: undefined + ): string; + encodeFunctionData(functionFragment: "owner", values?: undefined): string; + encodeFunctionData( + functionFragment: "refund", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "renounceOwnership", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "retrieveFund", + values: [AddressLike[], string] + ): string; + encodeFunctionData( + functionFragment: "transferFund", + values: [AddressLike, string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "transferOwnership", + values: [AddressLike] + ): string; + + decodeFunctionResult(functionFragment: "addLedger", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "depositFund", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "fineTuneAddress", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getAllLedgers", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "getLedger", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "inferenceAddress", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "initialize", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "initialized", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "owner", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "refund", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "renounceOwnership", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "retrieveFund", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "transferFund", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "transferOwnership", + data: BytesLike + ): Result; +} + +export namespace OwnershipTransferredEvent { + export type InputTuple = [previousOwner: AddressLike, newOwner: AddressLike]; + export type OutputTuple = [previousOwner: string, newOwner: string]; + export interface OutputObject { + previousOwner: string; + newOwner: string; + } + export type Event = TypedContractEvent; + export type Filter = TypedDeferredTopicFilter; + export type Log = TypedEventLog; + export type LogDescription = TypedLogDescription; +} + +export interface LedgerManager extends BaseContract { + connect(runner?: ContractRunner | null): LedgerManager; + waitForDeployment(): Promise; + + interface: LedgerManagerInterface; + + queryFilter( + event: TCEvent, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + queryFilter( + filter: TypedDeferredTopicFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + on( + event: TCEvent, + listener: TypedListener + ): Promise; + on( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + once( + event: TCEvent, + listener: TypedListener + ): Promise; + once( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + listeners( + event: TCEvent + ): Promise>>; + listeners(eventName?: string): Promise>; + removeAllListeners( + event?: TCEvent + ): Promise; + + addLedger: TypedContractMethod< + [signer: [BigNumberish, BigNumberish], additionalInfo: string], + [[bigint, bigint]], + "payable" + >; + + depositFund: TypedContractMethod<[], [void], "payable">; + + fineTuneAddress: TypedContractMethod<[], [string], "view">; + + getAllLedgers: TypedContractMethod<[], [LedgerStructOutput[]], "view">; + + getLedger: TypedContractMethod< + [user: AddressLike], + [LedgerStructOutput], + "view" + >; + + inferenceAddress: TypedContractMethod<[], [string], "view">; + + initialize: TypedContractMethod< + [ + _inferenceAddress: AddressLike, + _fineTuneAddress: AddressLike, + owner: AddressLike + ], + [void], + "nonpayable" + >; + + initialized: TypedContractMethod<[], [boolean], "view">; + + owner: TypedContractMethod<[], [string], "view">; + + refund: TypedContractMethod<[amount: BigNumberish], [void], "nonpayable">; + + renounceOwnership: TypedContractMethod<[], [void], "nonpayable">; + + retrieveFund: TypedContractMethod< + [providers: AddressLike[], serviceType: string], + [void], + "nonpayable" + >; + + transferFund: TypedContractMethod< + [provider: AddressLike, serviceType: string, amount: BigNumberish], + [void], + "nonpayable" + >; + + transferOwnership: TypedContractMethod< + [newOwner: AddressLike], + [void], + "nonpayable" + >; + + getFunction( + key: string | FunctionFragment + ): T; + + getFunction( + nameOrSignature: "addLedger" + ): TypedContractMethod< + [signer: [BigNumberish, BigNumberish], additionalInfo: string], + [[bigint, bigint]], + "payable" + >; + getFunction( + nameOrSignature: "depositFund" + ): TypedContractMethod<[], [void], "payable">; + getFunction( + nameOrSignature: "fineTuneAddress" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "getAllLedgers" + ): TypedContractMethod<[], [LedgerStructOutput[]], "view">; + getFunction( + nameOrSignature: "getLedger" + ): TypedContractMethod<[user: AddressLike], [LedgerStructOutput], "view">; + getFunction( + nameOrSignature: "inferenceAddress" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "initialize" + ): TypedContractMethod< + [ + _inferenceAddress: AddressLike, + _fineTuneAddress: AddressLike, + owner: AddressLike + ], + [void], + "nonpayable" + >; + getFunction( + nameOrSignature: "initialized" + ): TypedContractMethod<[], [boolean], "view">; + getFunction( + nameOrSignature: "owner" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "refund" + ): TypedContractMethod<[amount: BigNumberish], [void], "nonpayable">; + getFunction( + nameOrSignature: "renounceOwnership" + ): TypedContractMethod<[], [void], "nonpayable">; + getFunction( + nameOrSignature: "retrieveFund" + ): TypedContractMethod< + [providers: AddressLike[], serviceType: string], + [void], + "nonpayable" + >; + getFunction( + nameOrSignature: "transferFund" + ): TypedContractMethod< + [provider: AddressLike, serviceType: string, amount: BigNumberish], + [void], + "nonpayable" + >; + getFunction( + nameOrSignature: "transferOwnership" + ): TypedContractMethod<[newOwner: AddressLike], [void], "nonpayable">; + + getEvent( + key: "OwnershipTransferred" + ): TypedContractEvent< + OwnershipTransferredEvent.InputTuple, + OwnershipTransferredEvent.OutputTuple, + OwnershipTransferredEvent.OutputObject + >; + + filters: { + "OwnershipTransferred(address,address)": TypedContractEvent< + OwnershipTransferredEvent.InputTuple, + OwnershipTransferredEvent.OutputTuple, + OwnershipTransferredEvent.OutputObject + >; + OwnershipTransferred: TypedContractEvent< + OwnershipTransferredEvent.InputTuple, + OwnershipTransferredEvent.OutputTuple, + OwnershipTransferredEvent.OutputObject + >; + }; +} diff --git a/src.ts/contract/ledger/common.ts b/src.ts/contract/ledger/common.ts new file mode 100644 index 0000000..56b5f21 --- /dev/null +++ b/src.ts/contract/ledger/common.ts @@ -0,0 +1,131 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + FunctionFragment, + Typed, + EventFragment, + ContractTransaction, + ContractTransactionResponse, + DeferredTopicFilter, + EventLog, + TransactionRequest, + LogDescription, +} from "ethers"; + +export interface TypedDeferredTopicFilter<_TCEvent extends TypedContractEvent> + extends DeferredTopicFilter {} + +export interface TypedContractEvent< + InputTuple extends Array = any, + OutputTuple extends Array = any, + OutputObject = any +> { + (...args: Partial): TypedDeferredTopicFilter< + TypedContractEvent + >; + name: string; + fragment: EventFragment; + getFragment(...args: Partial): EventFragment; +} + +type __TypechainAOutputTuple = T extends TypedContractEvent< + infer _U, + infer W +> + ? W + : never; +type __TypechainOutputObject = T extends TypedContractEvent< + infer _U, + infer _W, + infer V +> + ? V + : never; + +export interface TypedEventLog + extends Omit { + args: __TypechainAOutputTuple & __TypechainOutputObject; +} + +export interface TypedLogDescription + extends Omit { + args: __TypechainAOutputTuple & __TypechainOutputObject; +} + +export type TypedListener = ( + ...listenerArg: [ + ...__TypechainAOutputTuple, + TypedEventLog, + ...undefined[] + ] +) => void; + +export type MinEthersFactory = { + deploy(...a: ARGS[]): Promise; +}; + +export type GetContractTypeFromFactory = F extends MinEthersFactory< + infer C, + any +> + ? C + : never; +export type GetARGsTypeFromFactory = F extends MinEthersFactory + ? Parameters + : never; + +export type StateMutability = "nonpayable" | "payable" | "view"; + +export type BaseOverrides = Omit; +export type NonPayableOverrides = Omit< + BaseOverrides, + "value" | "blockTag" | "enableCcipRead" +>; +export type PayableOverrides = Omit< + BaseOverrides, + "blockTag" | "enableCcipRead" +>; +export type ViewOverrides = Omit; +export type Overrides = S extends "nonpayable" + ? NonPayableOverrides + : S extends "payable" + ? PayableOverrides + : ViewOverrides; + +export type PostfixOverrides, S extends StateMutability> = + | A + | [...A, Overrides]; +export type ContractMethodArgs< + A extends Array, + S extends StateMutability +> = PostfixOverrides<{ [I in keyof A]-?: A[I] | Typed }, S>; + +export type DefaultReturnType = R extends Array ? R[0] : R; + +// export interface ContractMethod = Array, R = any, D extends R | ContractTransactionResponse = R | ContractTransactionResponse> { +export interface TypedContractMethod< + A extends Array = Array, + R = any, + S extends StateMutability = "payable" +> { + (...args: ContractMethodArgs): S extends "view" + ? Promise> + : Promise; + + name: string; + + fragment: FunctionFragment; + + getFragment(...args: ContractMethodArgs): FunctionFragment; + + populateTransaction( + ...args: ContractMethodArgs + ): Promise; + staticCall( + ...args: ContractMethodArgs + ): Promise>; + send(...args: ContractMethodArgs): Promise; + estimateGas(...args: ContractMethodArgs): Promise; + staticCallResult(...args: ContractMethodArgs): Promise; +} diff --git a/src.ts/contract/ledger/factories/LedgerManager__factory.ts b/src.ts/contract/ledger/factories/LedgerManager__factory.ts new file mode 100644 index 0000000..0a022d6 --- /dev/null +++ b/src.ts/contract/ledger/factories/LedgerManager__factory.ts @@ -0,0 +1,390 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { + Contract, + ContractFactory, + ContractTransactionResponse, + Interface, +} from "ethers"; +import type { Signer, ContractDeployTransaction, ContractRunner } from "ethers"; +import type { NonPayableOverrides } from "../common.js"; +import type { + LedgerManager, + LedgerManagerInterface, +} from "../LedgerManager.js"; + +const _abi = [ + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + ], + name: "InsufficientBalance", + type: "error", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + ], + name: "LedgerExists", + type: "error", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + ], + name: "LedgerNotExists", + type: "error", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "previousOwner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "OwnershipTransferred", + type: "event", + }, + { + inputs: [ + { + internalType: "uint256[2]", + name: "signer", + type: "uint256[2]", + }, + { + internalType: "string", + name: "additionalInfo", + type: "string", + }, + ], + name: "addLedger", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [], + name: "depositFund", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [], + name: "fineTuneAddress", + outputs: [ + { + internalType: "address payable", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getAllLedgers", + outputs: [ + { + components: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "uint256", + name: "availableBalance", + type: "uint256", + }, + { + internalType: "uint256", + name: "totalBalance", + type: "uint256", + }, + { + internalType: "uint256[2]", + name: "signer", + type: "uint256[2]", + }, + { + internalType: "string", + name: "additionalInfo", + type: "string", + }, + ], + internalType: "struct Ledger[]", + name: "accounts", + type: "tuple[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + ], + name: "getLedger", + outputs: [ + { + components: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "uint256", + name: "availableBalance", + type: "uint256", + }, + { + internalType: "uint256", + name: "totalBalance", + type: "uint256", + }, + { + internalType: "uint256[2]", + name: "signer", + type: "uint256[2]", + }, + { + internalType: "string", + name: "additionalInfo", + type: "string", + }, + ], + internalType: "struct Ledger", + name: "", + type: "tuple", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "inferenceAddress", + outputs: [ + { + internalType: "address payable", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_inferenceAddress", + type: "address", + }, + { + internalType: "address", + name: "_fineTuneAddress", + type: "address", + }, + { + internalType: "address", + name: "owner", + type: "address", + }, + ], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "initialized", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "owner", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "refund", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "renounceOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address[]", + name: "providers", + type: "address[]", + }, + { + internalType: "string", + name: "serviceType", + type: "string", + }, + ], + name: "retrieveFund", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "provider", + type: "address", + }, + { + internalType: "string", + name: "serviceType", + type: "string", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "transferFund", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, +] as const; + +const _bytecode = + "0x608060405234801561001057600080fd5b5061001a3361001f565b61006f565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6118288061007e6000396000f3fe6080604052600436106100dd5760003560e01c806372adc0d91161007f578063c0c53b8b11610059578063c0c53b8b14610237578063e5d9fdab14610257578063f2fde38b14610277578063f7cd6af91461029757600080fd5b806372adc0d9146101e95780638d0d8cb6146102115780638da5cb5b1461021957600080fd5b80632ba43b82116100bb5780632ba43b821461015c57806331404a191461017c57806352c00eb71461019c578063715018a6146101d457600080fd5b8063158ef93e146100e25780631665c79b14610118578063278ecde11461013a575b600080fd5b3480156100ee57600080fd5b5060005461010390600160a01b900460ff1681565b60405190151581526020015b60405180910390f35b34801561012457600080fd5b5061012d6102c4565b60405161010f91906111d2565b34801561014657600080fd5b5061015a610155366004611234565b610463565b005b34801561016857600080fd5b5061015a610177366004611320565b6104e7565b34801561018857600080fd5b5061015a610197366004611377565b610611565b3480156101a857600080fd5b506002546101bc906001600160a01b031681565b6040516001600160a01b03909116815260200161010f565b3480156101e057600080fd5b5061015a6106d2565b6101fc6101f7366004611446565b6106e6565b6040805192835260208301919091520161010f565b61015a610739565b34801561022557600080fd5b506000546001600160a01b03166101bc565b34801561024357600080fd5b5061015a61025236600461148f565b610798565b34801561026357600080fd5b506001546101bc906001600160a01b031681565b34801561028357600080fd5b5061015a6102923660046114d2565b610862565b3480156102a357600080fd5b506102b76102b23660046114d2565b6108db565b60405161010f91906114ed565b606060006102d06109e6565b90508067ffffffffffffffff8111156102eb576102eb611269565b60405190808252806020026020018201604052801561032457816020015b610311611076565b8152602001906001900390816103095790505b50915060005b8181101561045e5761033b816109f7565b6040805160a08101825282546001600160a01b031681526001830154602082015260028084015482840152825180840193849052919392606085019291600385019182845b81548152602001906001019080831161038057505050505081526020016005820180546103ac90611500565b80601f01602080910402602001604051908101604052809291908181526020018280546103d890611500565b80156104255780601f106103fa57610100808354040283529160200191610425565b820191906000526020600020905b81548152906001019060200180831161040857829003601f168201915b5050505050815250508382815181106104405761044061153a565b6020026020010181905250808061045690611566565b91505061032a565b505090565b600061046e33610a1a565b9050818160010154101561049c5760405163112fed8b60e31b81523360048201526024015b60405180910390fd5b818160010160008282546104b0919061157f565b9091555050604051339083156108fc029084906000818181858888f193505050501580156104e2573d6000803e3d6000fd5b505050565b60006104f233610a1a565b9050818160010154101561051b5760405163112fed8b60e31b8152336004820152602401610493565b60008360405160200161052e9190611592565b6040516020818303038152906040528051906020012090507f2a52b6261f3850b89541ab4444869004fe552e50532808641800076f8e9ec465810361058b576007546105869083906001600160a01b03168786610a6f565b61060a565b7f796fa12d30f6046c8d663bd4985181623031a418457cd73ac9146b182c5f8c8c81036105cb576006546105869083906001600160a01b03168786610a6f565b60405162461bcd60e51b8152602060048201526014602482015273496e76616c69642073657276696365207479706560601b6044820152606401610493565b5050505050565b600061061c33610a1a565b90506000826040516020016106319190611592565b6040516020818303038152906040528051906020012090507f2a52b6261f3850b89541ab4444869004fe552e50532808641800076f8e9ec465810361068d576007546106889083906001600160a01b031686610d34565b6106cc565b7f796fa12d30f6046c8d663bd4985181623031a418457cd73ac9146b182c5f8c8c81036105cb576006546106889083906001600160a01b031686610d34565b50505050565b6106da610e71565b6106e46000610ecb565b565b60008060006106f433610f1b565b90506106ff81610f4f565b1561071f5760405163cde58aa160e01b8152336004820152602401610493565b61072c8133873488610f62565b5034946000945092505050565b600061074433610f1b565b905061074f81610f4f565b61076e57604051637d2d536b60e01b8152336004820152602401610493565b600061077933610a1a565b90503481600101600082825461078f91906115ae565b90915550505050565b600054600160a01b900460ff16156107fd5760405162461bcd60e51b815260206004820152602260248201527f496e697469616c697a61626c653a20616c726561647920696e697469616c697a604482015261195960f21b6064820152608401610493565b6000805460ff60a01b1916600160a01b17905561081981610ecb565b50600180546001600160a01b039384166001600160a01b031991821681179092556002805493909416928116831790935560068054841690921790915560078054909216179055565b61086a610e71565b6001600160a01b0381166108cf5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610493565b6108d881610ecb565b50565b6108e3611076565b6108ec82610a1a565b6040805160a08101825282546001600160a01b031681526001830154602082015260028084015482840152825180840193849052919392606085019291600385019182845b815481526020019060010190808311610931575050505050815260200160058201805461095d90611500565b80601f016020809104026020016040519081016040528092919081815260200182805461098990611500565b80156109d65780601f106109ab576101008083540402835291602001916109d6565b820191906000526020600020905b8154815290600101906020018083116109b957829003601f168201915b5050505050815250509050919050565b60006109f26003610fc3565b905090565b600080610a05600384610fcd565b60009081526005602052604090209392505050565b600080610a2683610f1b565b6000818152600560205260409020909150610a4082610f4f565b610a6857604051637d2d536b60e01b81526001600160a01b0385166004820152602401610493565b9392505050565b80846001016000828254610a83919061157f565b909155505060405163147500e360e01b81523360048201526001600160a01b03838116602483015284169063147500e390604401602060405180830381865afa158015610ad4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610af891906115c1565b15610c17576001546040513360248201526001600160a01b0384811660448301526000921690839060640160408051601f198184030181529181526020820180516001600160e01b031663569a423960e11b17905251610b589190611592565b60006040518083038185875af1925050503d8060008114610b95576040519150601f19603f3d011682016040523d82523d6000602084013e610b9a565b606091505b5050905080610c115760405162461bcd60e51b815260206004820152603e60248201527f5472616e7366657220616e64206465706f73697446756e6442794c656467657260448201527f2063616c6c20746f206368696c6420636f6e7472616374206661696c656400006064820152608401610493565b506106cc565b6001546040516000916001600160a01b0316908390610c46903390879060038b019060058c01906024016115e3565b60408051601f198184030181529181526020820180516001600160e01b03166303802f4f60e11b17905251610c7b9190611592565b60006040518083038185875af1925050503d8060008114610cb8576040519150601f19603f3d011682016040523d82523d6000602084013e610cbd565b606091505b505090508061060a5760405162461bcd60e51b815260206004820152603d60248201527f5472616e7366657220616e64206164644163636f756e7442794c65646765722060448201527f63616c6c20746f206368696c6420636f6e7472616374206661696c65640000006064820152608401610493565b6000805b8251811015610e51576000838281518110610d5557610d5561153a565b602090810291909101015160405163271e279160e11b81523360048201526001600160a01b03808316602483015291925090861690634e3c4f22906044016060604051808303816000875af1158015610db2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd691906116b6565b5050604051636c79158d60e01b81523360048201526001600160a01b03838116602483015291945090861690636c79158d90604401600060405180830381600087803b158015610e2557600080fd5b505af1158015610e39573d6000803e3d6000fd5b50505050508080610e4990611566565b915050610d38565b5080846001016000828254610e6691906115ae565b909155505050505050565b6000546001600160a01b031633146106e45760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610493565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b604080516001600160a01b038316602082015260009101604051602081830303815290604052805190602001209050919050565b6000610f5c600383610fd9565b92915050565b60008581526005602052604090206001810183905580546001600160a01b0319166001600160a01b038616178155610f9f600382018560026110b4565b5060058101610fae8382611732565b50610fba600387610ff1565b50505050505050565b6000610f5c825490565b6000610a688383610ffd565b60008181526001830160205260408120541515610a68565b6000610a688383611027565b60008260000182815481106110145761101461153a565b9060005260206000200154905092915050565b600081815260018301602052604081205461106e57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610f5c565b506000610f5c565b6040518060a0016040528060006001600160a01b0316815260200160008152602001600081526020016110a76110f2565b8152602001606081525090565b82600281019282156110e2579160200282015b828111156110e25782358255916020019190600101906110c7565b506110ee929150611110565b5090565b60405180604001604052806002906020820280368337509192915050565b5b808211156110ee5760008155600101611111565b60005b83811015611140578181015183820152602001611128565b50506000910152565b80516001600160a01b031682526020808201518184015260408083015190840152606080830151600092918501835b600281101561119557825182529183019190830190600101611178565b505050608083015160c060a086015280518060c08701526111bc8160e08801858501611125565b601f01601f19169490940160e001949350505050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561122757603f19888603018452611215858351611149565b945092850192908501906001016111f9565b5092979650505050505050565b60006020828403121561124657600080fd5b5035919050565b80356001600160a01b038116811461126457600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156112a8576112a8611269565b604052919050565b600082601f8301126112c157600080fd5b813567ffffffffffffffff8111156112db576112db611269565b6112ee601f8201601f191660200161127f565b81815284602083860101111561130357600080fd5b816020850160208301376000918101602001919091529392505050565b60008060006060848603121561133557600080fd5b61133e8461124d565b9250602084013567ffffffffffffffff81111561135a57600080fd5b611366868287016112b0565b925050604084013590509250925092565b6000806040838503121561138a57600080fd5b823567ffffffffffffffff808211156113a257600080fd5b818501915085601f8301126113b657600080fd5b81356020828211156113ca576113ca611269565b8160051b6113d982820161127f565b928352848101820192828101908a8511156113f357600080fd5b958301955b84871015611418576114098761124d565b825295830195908301906113f8565b975050508601359250508082111561142f57600080fd5b5061143c858286016112b0565b9150509250929050565b6000806060838503121561145957600080fd5b604083018481111561146a57600080fd5b8392503567ffffffffffffffff81111561148357600080fd5b61143c858286016112b0565b6000806000606084860312156114a457600080fd5b6114ad8461124d565b92506114bb6020850161124d565b91506114c96040850161124d565b90509250925092565b6000602082840312156114e457600080fd5b610a688261124d565b602081526000610a686020830184611149565b600181811c9082168061151457607f821691505b60208210810361153457634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006001820161157857611578611550565b5060010190565b81810381811115610f5c57610f5c611550565b600082516115a4818460208701611125565b9190910192915050565b80820180821115610f5c57610f5c611550565b6000602082840312156115d357600080fd5b81518015158114610a6857600080fd5b6001600160a01b0385811682528416602080830191909152600090604083019085835b600281101561162357815484529282019260019182019101611606565b505060a0608085015260009150845461163b81611500565b8060a087015260c060018084166000811461165d5760018114611677576116a5565b60ff1985168984015283151560051b8901830196506116a5565b896000528560002060005b8581101561169d5781548b8201860152908301908701611682565b8a0184019750505b50949b9a5050505050505050505050565b6000806000606084860312156116cb57600080fd5b8351925060208401519150604084015190509250925092565b601f8211156104e257600081815260208120601f850160051c8101602086101561170b5750805b601f850160051c820191505b8181101561172a57828155600101611717565b505050505050565b815167ffffffffffffffff81111561174c5761174c611269565b6117608161175a8454611500565b846116e4565b602080601f831160018114611795576000841561177d5750858301515b600019600386901b1c1916600185901b17855561172a565b600085815260208120601f198616915b828110156117c4578886015182559484019460019091019084016117a5565b50858210156117e25787850151600019600388901b60f8161c191681555b5050505050600190811b0190555056fea26469706673582212202521cc0dc3e596490a434c1e5220db32dca1377821c9a3736932759600dd1b4464736f6c63430008140033"; + +type LedgerManagerConstructorParams = + | [signer?: Signer] + | ConstructorParameters; + +const isSuperArgs = ( + xs: LedgerManagerConstructorParams +): xs is ConstructorParameters => xs.length > 1; + +export class LedgerManager__factory extends ContractFactory { + constructor(...args: LedgerManagerConstructorParams) { + if (isSuperArgs(args)) { + super(...args); + } else { + super(_abi, _bytecode, args[0]); + } + } + + override getDeployTransaction( + overrides?: NonPayableOverrides & { from?: string } + ): Promise { + return super.getDeployTransaction(overrides || {}); + } + override deploy(overrides?: NonPayableOverrides & { from?: string }) { + return super.deploy(overrides || {}) as Promise< + LedgerManager & { + deploymentTransaction(): ContractTransactionResponse; + } + >; + } + override connect(runner: ContractRunner | null): LedgerManager__factory { + return super.connect(runner) as LedgerManager__factory; + } + + static readonly bytecode = _bytecode; + static readonly abi = _abi; + static createInterface(): LedgerManagerInterface { + return new Interface(_abi) as LedgerManagerInterface; + } + static connect( + address: string, + runner?: ContractRunner | null + ): LedgerManager { + return new Contract(address, _abi, runner) as unknown as LedgerManager; + } +} diff --git a/src.ts/contract/serving/factories/index.ts b/src.ts/contract/ledger/factories/index.ts similarity index 56% rename from src.ts/contract/serving/factories/index.ts rename to src.ts/contract/ledger/factories/index.ts index 03dbcee..6d63e46 100644 --- a/src.ts/contract/serving/factories/index.ts +++ b/src.ts/contract/ledger/factories/index.ts @@ -1,4 +1,4 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ -export { Serving__factory } from "./Serving__factory.js"; +export { LedgerManager__factory } from "./LedgerManager__factory.js"; diff --git a/src.ts/contract/serving/index.ts b/src.ts/contract/ledger/index.ts similarity index 50% rename from src.ts/contract/serving/index.ts rename to src.ts/contract/ledger/index.ts index f912861..62b6c41 100644 --- a/src.ts/contract/serving/index.ts +++ b/src.ts/contract/ledger/index.ts @@ -1,6 +1,6 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ -export type { Serving } from "./Serving.js"; +export type { LedgerManager } from "./LedgerManager.js"; export * as factories from "./factories/index.js"; -export { Serving__factory } from "./factories/Serving__factory.js"; +export { LedgerManager__factory } from "./factories/LedgerManager__factory.js"; diff --git a/src.ts/contract/serving/factories/Serving__factory.ts b/src.ts/contract/serving/factories/Serving__factory.ts deleted file mode 100644 index 7144fb4..0000000 --- a/src.ts/contract/serving/factories/Serving__factory.ts +++ /dev/null @@ -1,953 +0,0 @@ -/* Autogenerated file. Do not edit manually. */ -/* tslint:disable */ -/* eslint-disable */ -import { - Contract, - ContractFactory, - ContractTransactionResponse, - Interface, -} from "ethers"; -import type { Signer, ContractDeployTransaction, ContractRunner } from "ethers"; -import type { NonPayableOverrides } from "../common.js"; -import type { Serving, ServingInterface } from "../Serving.js"; - -const _abi = [ - { - inputs: [ - { - internalType: "address", - name: "user", - type: "address", - }, - { - internalType: "address", - name: "provider", - type: "address", - }, - ], - name: "AccountExists", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "user", - type: "address", - }, - { - internalType: "address", - name: "provider", - type: "address", - }, - ], - name: "AccountNotexists", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "user", - type: "address", - }, - { - internalType: "address", - name: "provider", - type: "address", - }, - ], - name: "InsufficientBalance", - type: "error", - }, - { - inputs: [ - { - internalType: "string", - name: "reason", - type: "string", - }, - ], - name: "InvalidProofInputs", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "user", - type: "address", - }, - { - internalType: "address", - name: "provider", - type: "address", - }, - { - internalType: "uint256", - name: "index", - type: "uint256", - }, - ], - name: "RefundInvalid", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "user", - type: "address", - }, - { - internalType: "address", - name: "provider", - type: "address", - }, - { - internalType: "uint256", - name: "index", - type: "uint256", - }, - ], - name: "RefundLocked", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "user", - type: "address", - }, - { - internalType: "address", - name: "provider", - type: "address", - }, - { - internalType: "uint256", - name: "index", - type: "uint256", - }, - ], - name: "RefundProcessed", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "provider", - type: "address", - }, - { - internalType: "string", - name: "name", - type: "string", - }, - ], - name: "ServiceNotexist", - type: "error", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "user", - type: "address", - }, - { - indexed: true, - internalType: "address", - name: "provider", - type: "address", - }, - { - indexed: false, - internalType: "uint256", - name: "amount", - type: "uint256", - }, - { - indexed: false, - internalType: "uint256", - name: "pendingRefund", - type: "uint256", - }, - ], - name: "BalanceUpdated", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "previousOwner", - type: "address", - }, - { - indexed: true, - internalType: "address", - name: "newOwner", - type: "address", - }, - ], - name: "OwnershipTransferred", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "user", - type: "address", - }, - { - indexed: true, - internalType: "address", - name: "provider", - type: "address", - }, - { - indexed: true, - internalType: "uint256", - name: "index", - type: "uint256", - }, - { - indexed: false, - internalType: "uint256", - name: "timestamp", - type: "uint256", - }, - ], - name: "RefundRequested", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "service", - type: "address", - }, - { - indexed: true, - internalType: "string", - name: "name", - type: "string", - }, - ], - name: "ServiceRemoved", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "service", - type: "address", - }, - { - indexed: true, - internalType: "string", - name: "name", - type: "string", - }, - { - indexed: false, - internalType: "string", - name: "serviceType", - type: "string", - }, - { - indexed: false, - internalType: "string", - name: "url", - type: "string", - }, - { - indexed: false, - internalType: "uint256", - name: "inputPrice", - type: "uint256", - }, - { - indexed: false, - internalType: "uint256", - name: "outputPrice", - type: "uint256", - }, - { - indexed: false, - internalType: "uint256", - name: "updatedAt", - type: "uint256", - }, - { - indexed: false, - internalType: "string", - name: "model", - type: "string", - }, - { - indexed: false, - internalType: "string", - name: "verifiability", - type: "string", - }, - ], - name: "ServiceUpdated", - type: "event", - }, - { - inputs: [ - { - internalType: "address", - name: "provider", - type: "address", - }, - { - internalType: "uint256[2]", - name: "signer", - type: "uint256[2]", - }, - { - internalType: "string", - name: "additionalInfo", - type: "string", - }, - ], - name: "addAccount", - outputs: [], - stateMutability: "payable", - type: "function", - }, - { - inputs: [ - { - internalType: "string", - name: "name", - type: "string", - }, - { - internalType: "string", - name: "serviceType", - type: "string", - }, - { - internalType: "string", - name: "url", - type: "string", - }, - { - internalType: "string", - name: "model", - type: "string", - }, - { - internalType: "string", - name: "verifiability", - type: "string", - }, - { - internalType: "uint256", - name: "inputPrice", - type: "uint256", - }, - { - internalType: "uint256", - name: "outputPrice", - type: "uint256", - }, - ], - name: "addOrUpdateService", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "batchVerifierAddress", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "provider", - type: "address", - }, - ], - name: "deleteAccount", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "provider", - type: "address", - }, - ], - name: "depositFund", - outputs: [], - stateMutability: "payable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "user", - type: "address", - }, - { - internalType: "address", - name: "provider", - type: "address", - }, - ], - name: "getAccount", - outputs: [ - { - components: [ - { - internalType: "address", - name: "user", - type: "address", - }, - { - internalType: "address", - name: "provider", - type: "address", - }, - { - internalType: "uint256", - name: "nonce", - type: "uint256", - }, - { - internalType: "uint256", - name: "balance", - type: "uint256", - }, - { - internalType: "uint256", - name: "pendingRefund", - type: "uint256", - }, - { - internalType: "uint256[2]", - name: "signer", - type: "uint256[2]", - }, - { - components: [ - { - internalType: "uint256", - name: "index", - type: "uint256", - }, - { - internalType: "uint256", - name: "amount", - type: "uint256", - }, - { - internalType: "uint256", - name: "createdAt", - type: "uint256", - }, - { - internalType: "bool", - name: "processed", - type: "bool", - }, - ], - internalType: "struct Refund[]", - name: "refunds", - type: "tuple[]", - }, - { - internalType: "string", - name: "additionalInfo", - type: "string", - }, - ], - internalType: "struct Account", - name: "", - type: "tuple", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getAllAccounts", - outputs: [ - { - components: [ - { - internalType: "address", - name: "user", - type: "address", - }, - { - internalType: "address", - name: "provider", - type: "address", - }, - { - internalType: "uint256", - name: "nonce", - type: "uint256", - }, - { - internalType: "uint256", - name: "balance", - type: "uint256", - }, - { - internalType: "uint256", - name: "pendingRefund", - type: "uint256", - }, - { - internalType: "uint256[2]", - name: "signer", - type: "uint256[2]", - }, - { - components: [ - { - internalType: "uint256", - name: "index", - type: "uint256", - }, - { - internalType: "uint256", - name: "amount", - type: "uint256", - }, - { - internalType: "uint256", - name: "createdAt", - type: "uint256", - }, - { - internalType: "bool", - name: "processed", - type: "bool", - }, - ], - internalType: "struct Refund[]", - name: "refunds", - type: "tuple[]", - }, - { - internalType: "string", - name: "additionalInfo", - type: "string", - }, - ], - internalType: "struct Account[]", - name: "", - type: "tuple[]", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getAllServices", - outputs: [ - { - components: [ - { - internalType: "address", - name: "provider", - type: "address", - }, - { - internalType: "string", - name: "name", - type: "string", - }, - { - internalType: "string", - name: "serviceType", - type: "string", - }, - { - internalType: "string", - name: "url", - type: "string", - }, - { - internalType: "uint256", - name: "inputPrice", - type: "uint256", - }, - { - internalType: "uint256", - name: "outputPrice", - type: "uint256", - }, - { - internalType: "uint256", - name: "updatedAt", - type: "uint256", - }, - { - internalType: "string", - name: "model", - type: "string", - }, - { - internalType: "string", - name: "verifiability", - type: "string", - }, - ], - internalType: "struct Service[]", - name: "services", - type: "tuple[]", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "provider", - type: "address", - }, - { - internalType: "string", - name: "name", - type: "string", - }, - ], - name: "getService", - outputs: [ - { - components: [ - { - internalType: "address", - name: "provider", - type: "address", - }, - { - internalType: "string", - name: "name", - type: "string", - }, - { - internalType: "string", - name: "serviceType", - type: "string", - }, - { - internalType: "string", - name: "url", - type: "string", - }, - { - internalType: "uint256", - name: "inputPrice", - type: "uint256", - }, - { - internalType: "uint256", - name: "outputPrice", - type: "uint256", - }, - { - internalType: "uint256", - name: "updatedAt", - type: "uint256", - }, - { - internalType: "string", - name: "model", - type: "string", - }, - { - internalType: "string", - name: "verifiability", - type: "string", - }, - ], - internalType: "struct Service", - name: "service", - type: "tuple", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_locktime", - type: "uint256", - }, - { - internalType: "address", - name: "_batchVerifierAddress", - type: "address", - }, - { - internalType: "address", - name: "owner", - type: "address", - }, - ], - name: "initialize", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "initialized", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "lockTime", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "owner", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "provider", - type: "address", - }, - { - internalType: "uint256[]", - name: "indices", - type: "uint256[]", - }, - ], - name: "processRefund", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "string", - name: "name", - type: "string", - }, - ], - name: "removeService", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "renounceOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "provider", - type: "address", - }, - { - internalType: "uint256", - name: "amount", - type: "uint256", - }, - ], - name: "requestRefund", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - components: [ - { - internalType: "uint256[]", - name: "inProof", - type: "uint256[]", - }, - { - internalType: "uint256[]", - name: "proofInputs", - type: "uint256[]", - }, - { - internalType: "uint256", - name: "numChunks", - type: "uint256", - }, - { - internalType: "uint256[]", - name: "segmentSize", - type: "uint256[]", - }, - ], - internalType: "struct VerifierInput", - name: "verifierInput", - type: "tuple", - }, - ], - name: "settleFees", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "newOwner", - type: "address", - }, - ], - name: "transferOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "_batchVerifierAddress", - type: "address", - }, - ], - name: "updateBatchVerifierAddress", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_locktime", - type: "uint256", - }, - ], - name: "updateLockTime", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, -] as const; - -const _bytecode = - "0x60806040523480156200001157600080fd5b506200001d3362000023565b62000073565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b61339b80620000836000396000f3fe60806040526004361061012a5760003560e01c8063715018a6116100ab578063b4988fd01161006f578063b4988fd01461033e578063e12d4a521461035e578063f2fde38b14610371578063f51acaea14610391578063fbfa4e11146103b1578063fd590847146103d157600080fd5b8063715018a6146102ab578063746e78d7146102c057806378c00436146102e05780638da5cb5b1461030057806399652de71461031e57600080fd5b806321fe0f30116100f257806321fe0f30146101f1578063371c22c5146102135780634c1b64cb1461024b5780634da824a81461026b5780636341b2d11461028b57600080fd5b806308e93d0a1461012f5780630b1d13921461015a5780630d6680871461016f5780630e61d15814610193578063158ef93e146101c0575b600080fd5b34801561013b57600080fd5b506101446103fe565b60405161015191906129a2565b60405180910390f35b61016d610168366004612ac3565b61040f565b005b34801561017b57600080fd5b5061018560015481565b604051908152602001610151565b34801561019f57600080fd5b506101b36101ae366004612b26565b610462565b6040516101519190612c24565b3480156101cc57600080fd5b506000546101e190600160a01b900460ff1681565b6040519015158152602001610151565b3480156101fd57600080fd5b50610206610797565b6040516101519190612c37565b34801561021f57600080fd5b50600254610233906001600160a01b031681565b6040516001600160a01b039091168152602001610151565b34801561025757600080fd5b5061016d610266366004612c8c565b6107a3565b34801561027757600080fd5b5061016d610286366004612ca7565b6107b2565b34801561029757600080fd5b5061016d6102a6366004612d76565b610870565b3480156102b757600080fd5b5061016d61099b565b3480156102cc57600080fd5b5061016d6102db366004612c8c565b6109af565b3480156102ec57600080fd5b5061016d6102fb366004612e6b565b6109e3565b34801561030c57600080fd5b506000546001600160a01b0316610233565b34801561032a57600080fd5b5061016d610339366004612ea6565b611000565b34801561034a57600080fd5b5061016d610359366004612ed0565b611064565b61016d61036c366004612c8c565b611118565b34801561037d57600080fd5b5061016d61038c366004612c8c565b611167565b34801561039d57600080fd5b5061016d6103ac366004612f0c565b6111dd565b3480156103bd57600080fd5b5061016d6103cc366004612f41565b61122c565b3480156103dd57600080fd5b506103f16103ec366004612f5a565b611239565b6040516101519190612f8d565b606061040a6004611362565b905090565b600080610421600433878734886115a3565b60408051838152602081018390529294509092506001600160a01b038716913391600080516020613346833981519152910160405180910390a35050505050565b61046a61269e565b6104766007848461160e565b60408051610120810190915281546001600160a01b031681526001820180549192916020840191906104a790612fa0565b80601f01602080910402602001604051908101604052809291908181526020018280546104d390612fa0565b80156105205780601f106104f557610100808354040283529160200191610520565b820191906000526020600020905b81548152906001019060200180831161050357829003601f168201915b5050505050815260200160028201805461053990612fa0565b80601f016020809104026020016040519081016040528092919081815260200182805461056590612fa0565b80156105b25780601f10610587576101008083540402835291602001916105b2565b820191906000526020600020905b81548152906001019060200180831161059557829003601f168201915b505050505081526020016003820180546105cb90612fa0565b80601f01602080910402602001604051908101604052809291908181526020018280546105f790612fa0565b80156106445780601f1061061957610100808354040283529160200191610644565b820191906000526020600020905b81548152906001019060200180831161062757829003601f168201915b5050505050815260200160048201548152602001600582015481526020016006820154815260200160078201805461067b90612fa0565b80601f01602080910402602001604051908101604052809291908181526020018280546106a790612fa0565b80156106f45780601f106106c9576101008083540402835291602001916106f4565b820191906000526020600020905b8154815290600101906020018083116106d757829003601f168201915b5050505050815260200160088201805461070d90612fa0565b80601f016020809104026020016040519081016040528092919081815260200182805461073990612fa0565b80156107865780601f1061075b57610100808354040283529160200191610786565b820191906000526020600020905b81548152906001019060200180831161076957829003601f168201915b505050505081525050905092915050565b606061040a6007611623565b6107af600433836119e3565b50565b60008060006107fe338787878080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050600154600495949392509050611aa9565b6040519295509093509150339084156108fc029085906000818181858888f19350505050158015610833573d6000803e3d6000fd5b5060408051838152602081018390526001600160a01b038816913391600080516020613346833981519152910160405180910390a3505050505050565b610926338b8b8b8b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8f018190048102820181019092528d815292508d91508c908190840183828082843760009201919091525050604080516020601f8e018190048102820181019092528c815292508c91508b9081908401838280828437600092019190915250600798979695949392508b91508a9050611c6b565b896040516109349190612fda565b6040518091039020336001600160a01b03167f95e1ef74a36b7d6ac766d338a4468c685d593739c3b7dc39e2aa5921a1e139328b8b8b8787428e8e8e8e6040516109879a9998979695949392919061301f565b60405180910390a350505050505050505050565b6109a3611d5d565b6109ad6000611db7565b565b6109b7611d5d565b600280546001600160a01b039092166001600160a01b0319928316811790915560038054909216179055565b6003546000906001600160a01b031663ad12259a610a018480613092565b610a0e6020870187613092565b87604001356040518663ffffffff1660e01b8152600401610a3395949392919061310e565b602060405180830381865afa158015610a50573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a749190613148565b905080610ac95760405163885e287960e01b815260206004820152601f60248201527f5a4b20736574746c656d656e742076616c69646174696f6e206661696c65640060448201526064015b60405180910390fd5b6000610ad86020840184613092565b808060200260200160405190810160405280939291908181526020018383602002808284376000920182905250939450339250839150505b610b1d6060870187613092565b9050811015610f8a576000610b356060880188613092565b83818110610b4557610b4561316a565b90506020020135905060008185610b5c9190613196565b9050600080878781518110610b7357610b7361316a565b60200260200101519050600088886002610b8d9190613196565b81518110610b9d57610b9d61316a565b60200260200101519050600089896003610bb79190613196565b81518110610bc757610bc761316a565b602002602001015190506000610be984336004611e079092919063ffffffff16565b90508a610bf78b6005613196565b81518110610c0757610c0761316a565b602002602001015181600501600060028110610c2557610c2561316a565b0154141580610c6e57508a610c3b8b6006613196565b81518110610c4b57610c4b61316a565b602002602001015181600501600160028110610c6957610c6961316a565b015414155b15610cbc5760405163885e287960e01b815260206004820152601760248201527f7369676e6572206b657920697320696e636f72726563740000000000000000006044820152606401610ac0565b8281600201541115610d115760405163885e287960e01b815260206004820152601a60248201527f696e697469616c206e6f6e636520697320696e636f72726563740000000000006044820152606401610ac0565b895b86811015610f135760008c8281518110610d2f57610d2f61316a565b6020026020010151905060008d836001610d499190613196565b81518110610d5957610d5961316a565b602002602001015190508d836003610d719190613196565b81518110610d8157610d8161316a565b6020026020010151945060008e846004610d9b9190613196565b81518110610dab57610dab61316a565b6020026020010151905060008a856009610dc59190613196565b10610dd1576000610df6565b8f610ddd866009613196565b81518110610ded57610ded61316a565b60200260200101515b90508015801590610e075750808710155b15610e485760405163885e287960e01b815260206004820152601060248201526f1b9bdb98d9481bdd995c9b185c1c195960821b6044820152606401610ac0565b8884141580610e5757508d8314155b15610eef57888403610e9e576040518060400160405280601d81526020017f70726f7669646572206164647265737320697320696e636f7272656374000000815250610ed5565b6040518060400160405280601981526020017f75736572206164647265737320697320696e636f7272656374000000000000008152505b60405163885e287960e01b8152600401610ac091906131a9565b610ef9828b613196565b995050505050600781610f0c9190613196565b9050610d13565b508481600301541015610f605760405163885e287960e01b8152602060048201526014602482015273696e73756666696369656e742062616c616e636560601b6044820152606401610ac0565b610f6a8186611e14565b6002015550919550839250610f8291508290506131bc565b915050610b10565b5082518214610ff95760405163885e287960e01b815260206004820152603460248201527f6172726179207365676d656e7453697a652073756d206d69736d617463686573604482015273040e0eac4d8d2c640d2dce0eae840d8cadccee8d60631b6064820152608401610ac0565b5050505050565b600061100f600433858561201d565b905080836001600160a01b0316336001600160a01b03167f54377dfdebf06f6df53fbda737d2dcd7e141f95bbfb0c1223437e856b9de3ac34260405161105791815260200190565b60405180910390a4505050565b600054600160a01b900460ff16156110c95760405162461bcd60e51b815260206004820152602260248201527f496e697469616c697a61626c653a20616c726561647920696e697469616c697a604482015261195960f21b6064820152608401610ac0565b6000805460ff60a01b1916600160a01b1790556110e581611db7565b50600191909155600280546001600160a01b039092166001600160a01b0319928316811790915560038054909216179055565b6000806111286004338534612113565b60408051838152602081018390529294509092506001600160a01b038516913391600080516020613346833981519152910160405180910390a3505050565b61116f611d5d565b6001600160a01b0381166111d45760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610ac0565b6107af81611db7565b6111e96007338361219f565b806040516111f79190612fda565b6040519081900381209033907f68026479739e3662c0651578523384b94455e79bfb701ce111a3164591ceba7390600090a350565b611234611d5d565b600155565b6112416126f3565b61124d60048484611e07565b604080516101008101825282546001600160a01b039081168252600184015416602082015260028084015482840152600384015460608301526004840154608083015282518084019384905291939260a085019291600585019182845b8154815260200190600101908083116112aa575050505050815260200160078201805480602002602001604051908101604052809291908181526020016000905b82821015611344576000848152602090819020604080516080810182526004860290920180548352600180820154848601526002820154928401929092526003015460ff161515606083015290835290920191016112eb565b50505050815260200160088201805461070d90612fa0565b92915050565b6060600061136f836121e2565b90508067ffffffffffffffff81111561138a5761138a612a20565b6040519080825280602002602001820160405280156113c357816020015b6113b06126f3565b8152602001906001900390816113a85790505b50915060005b8181101561159c576113db84826121ed565b604080516101008101825282546001600160a01b039081168252600184015416602082015260028084015482840152600384015460608301526004840154608083015282518084019384905291939260a085019291600585019182845b815481526020019060010190808311611438575050505050815260200160078201805480602002602001604051908101604052809291908181526020016000905b828210156114d2576000848152602090819020604080516080810182526004860290920180548352600180820154848601526002820154928401929092526003015460ff16151560608301529083529092019101611479565b5050505081526020016008820180546114ea90612fa0565b80601f016020809104026020016040519081016040528092919081815260200182805461151690612fa0565b80156115635780601f1061153857610100808354040283529160200191611563565b820191906000526020600020905b81548152906001019060200180831161154657829003601f168201915b50505050508152505083828151811061157e5761157e61316a565b60200260200101819052508080611594906131bc565b9150506113c9565b5050919050565b60008060006115b28888612213565b90506115be8982612255565b156115ef57604051632cf0675960e21b81526001600160a01b03808a16600483015288166024820152604401610ac0565b6115fe89828a8a8a8a8a612268565b5092976000975095505050505050565b600061161b8484846122d8565b949350505050565b60606000611630836121e2565b90508067ffffffffffffffff81111561164b5761164b612a20565b60405190808252806020026020018201604052801561168457816020015b61167161269e565b8152602001906001900390816116695790505b50915060005b8181101561159c5761169c84826121ed565b60408051610120810190915281546001600160a01b031681526001820180549192916020840191906116cd90612fa0565b80601f01602080910402602001604051908101604052809291908181526020018280546116f990612fa0565b80156117465780601f1061171b57610100808354040283529160200191611746565b820191906000526020600020905b81548152906001019060200180831161172957829003601f168201915b5050505050815260200160028201805461175f90612fa0565b80601f016020809104026020016040519081016040528092919081815260200182805461178b90612fa0565b80156117d85780601f106117ad576101008083540402835291602001916117d8565b820191906000526020600020905b8154815290600101906020018083116117bb57829003601f168201915b505050505081526020016003820180546117f190612fa0565b80601f016020809104026020016040519081016040528092919081815260200182805461181d90612fa0565b801561186a5780601f1061183f5761010080835404028352916020019161186a565b820191906000526020600020905b81548152906001019060200180831161184d57829003601f168201915b505050505081526020016004820154815260200160058201548152602001600682015481526020016007820180546118a190612fa0565b80601f01602080910402602001604051908101604052809291908181526020018280546118cd90612fa0565b801561191a5780601f106118ef5761010080835404028352916020019161191a565b820191906000526020600020905b8154815290600101906020018083116118fd57829003601f168201915b5050505050815260200160088201805461193390612fa0565b80601f016020809104026020016040519081016040528092919081815260200182805461195f90612fa0565b80156119ac5780601f10611981576101008083540402835291602001916119ac565b820191906000526020600020905b81548152906001019060200180831161198f57829003601f168201915b5050505050815250508382815181106119c7576119c761316a565b6020026020010181905250806119dc906131bc565b905061168a565b60006119ef8383612213565b90506119fb8482612255565b611a2b57604051637e01ed7f60e01b81526001600160a01b03808516600483015283166024820152604401610ac0565b611a35848261232c565b50600081815260028086016020526040822080546001600160a01b0319908116825560018201805490911690559081018290556003810182905560048101829055600581018290556006810182905590611a93600783016000612750565b611aa1600883016000612771565b505050505050565b600080600080611aba898989612338565b90506000935060005b8651811015611c50576000878281518110611ae057611ae061316a565b6020026020010151905082600701805490508110611b2b57604051637621e3f760e11b81526001600160a01b03808c1660048301528a16602482015260448101829052606401610ac0565b6000836007018281548110611b4257611b4261316a565b60009182526020909120600490910201600381015490915060ff1615611b9557604051633cf6bf4160e01b81526001600160a01b03808d1660048301528b16602482015260448101839052606401610ac0565b878160020154611ba59190613196565b421015611bdf57604051631779e03760e31b81526001600160a01b03808d1660048301528b16602482015260448101839052606401610ac0565b8060010154846003016000828254611bf791906131d5565b90915550506001810154600485018054600090611c159084906131d5565b909155505060038101805460ff19166001908117909155810154611c399088613196565b965050508080611c48906131bc565b915050611ac3565b50806003015492508060040154915050955095509592505050565b6000611c778989612392565b9050611c838a82612255565b611ce157611cda8a826040518061012001604052808d6001600160a01b031681526020018c81526020018b81526020018a8152602001878152602001868152602001428152602001898152602001888152506123a7565b5050611d52565b6000611cee8b8b8b6122d8565b905060018101611cfe8a8261322e565b5060028101611d0d898261322e565b50600481018490556005810183905560038101611d2a888261322e565b5042600682015560078101611d3f878261322e565b5060088101611d4e868261322e565b5050505b505050505050505050565b6000546001600160a01b031633146109ad5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610ac0565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600061161b848484612338565b81600401548260030154611e2891906131d5565b811115611f8d57600082600401548360030154611e4591906131d5565b611e4f90836131d5565b90508083600401541015611eb45760405163885e287960e01b815260206004820152602560248201527f696e73756666696369656e742062616c616e636520696e2070656e64696e675260448201526419599d5b9960da1b6064820152608401610ac0565b80836004016000828254611ec891906131d5565b90915550506007830154600090611ee1906001906131d5565b90505b60008112611f8a576000846007018281548110611f0357611f0361316a565b60009182526020909120600490910201600381015490915060ff1615611f295750611f78565b82816001015411611f4a576001810154611f4390846131d5565b9250611f68565b82816001016000828254611f5e91906131d5565b9091555060009350505b82600003611f765750611f8a565b505b80611f82816132ee565b915050611ee4565b50505b80826003016000828254611fa191906131d5565b909155505081546003830154600484015460405133936001600160a01b03169260008051602061334683398151915292611fe392918252602082015260400190565b60405180910390a3604051339082156108fc029083906000818181858888f19350505050158015612018573d6000803e3d6000fd5b505050565b60008061202b868686612338565b9050828160040154826003015461204291906131d5565b101561207457604051630a542ddd60e31b81526001600160a01b03808716600483015285166024820152604401610ac0565b6040805160808101825260078301805480835260208084018881524295850195865260006060860181815260018086018755958252928120955160049485029096019586559051938501939093559351600284015592516003909201805460ff19169215159290921790915590820180548592906120f3908490613196565b90915550506007810154612109906001906131d5565b9695505050505050565b60008060006121228686612213565b905061212e8782612255565b61215e57604051637e01ed7f60e01b81526001600160a01b03808816600483015286166024820152604401610ac0565b600061216b888888612338565b9050848160030160008282546121819190613196565b90915550506003810154600490910154909890975095505050505050565b60006121ab8383612392565b90506121b78482612255565b6121d857828260405163edefcd8360e01b8152600401610ac092919061330b565b610ff9848261246d565b600061135c826124f8565b6000806121fa8484612502565b6000908152600285016020526040902091505092915050565b604080516001600160a01b0380851660208301528316918101919091526000906060015b60405160208183030381529060405280519060200120905092915050565b6000612261838361250e565b9392505050565b6000868152600280890160205260409091206003810184905580546001600160a01b038089166001600160a01b031992831617835560018301805491891691909216179055906122be90600583019086906127ab565b50600881016122cd838261322e565b50611d528888612526565b6000806122e58484612392565b600081815260028701602052604090209091506123028683612255565b61232357848460405163edefcd8360e01b8152600401610ac092919061330b565b95945050505050565b60006122618383612532565b6000806123458484612213565b600081815260028701602052604090209091506123628683612255565b61232357604051637e01ed7f60e01b81526001600160a01b03808716600483015285166024820152604401610ac0565b6000828260405160200161223792919061330b565b600082815260028401602090815260408220835181546001600160a01b0319166001600160a01b039091161781559083015183919060018201906123eb908261322e565b5060408201516002820190612400908261322e565b5060608201516003820190612415908261322e565b506080820151600482015560a0820151600582015560c0820151600682015560e08201516007820190612448908261322e565b50610100820151600882019061245e908261322e565b5061161b915085905084612526565b6000818152600283016020526040812080546001600160a01b0319168155816124996001830182612771565b6124a7600283016000612771565b6124b5600383016000612771565b6004820160009055600582016000905560068201600090556007820160006124dd9190612771565b6124eb600883016000612771565b506122619050838361232c565b600061135c825490565b60006122618383612625565b60008181526001830160205260408120541515612261565b6000612261838361264f565b6000818152600183016020526040812054801561261b5760006125566001836131d5565b855490915060009061256a906001906131d5565b90508181146125cf57600086600001828154811061258a5761258a61316a565b90600052602060002001549050808760000184815481106125ad576125ad61316a565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806125e0576125e061332f565b60019003818190600052602060002001600090559055856001016000868152602001908152602001600020600090556001935050505061135c565b600091505061135c565b600082600001828154811061263c5761263c61316a565b9060005260206000200154905092915050565b60008181526001830160205260408120546126965750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561135c565b50600061135c565b60405180610120016040528060006001600160a01b0316815260200160608152602001606081526020016060815260200160008152602001600081526020016000815260200160608152602001606081525090565b60405180610100016040528060006001600160a01b0316815260200160006001600160a01b0316815260200160008152602001600081526020016000815260200161273c6127e9565b815260200160608152602001606081525090565b50805460008255600402906000526020600020908101906107af9190612807565b50805461277d90612fa0565b6000825580601f1061278d575050565b601f0160209004906000526020600020908101906107af9190612835565b82600281019282156127d9579160200282015b828111156127d95782358255916020019190600101906127be565b506127e5929150612835565b5090565b60405180604001604052806002906020820280368337509192915050565b5b808211156127e557600080825560018201819055600282015560038101805460ff19169055600401612808565b5b808211156127e55760008155600101612836565b8060005b600281101561286d57815184526020938401939091019060010161284e565b50505050565b600081518084526020808501945080840160005b838110156128c55781518051885283810151848901526040808201519089015260609081015115159088015260809096019590820190600101612887565b509495945050505050565b60005b838110156128eb5781810151838201526020016128d3565b50506000910152565b6000815180845261290c8160208601602086016128d0565b601f01601f19169290920160200192915050565b600061012060018060a01b038084511685528060208501511660208601525060408301516040850152606083015160608501526080830151608085015260a083015161296f60a086018261284a565b5060c08301518160e086015261298782860182612873565b91505060e083015184820361010086015261232382826128f4565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b828110156129f757603f198886030184526129e5858351612920565b945092850192908501906001016129c9565b5092979650505050505050565b80356001600160a01b0381168114612a1b57600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b600082601f830112612a4757600080fd5b813567ffffffffffffffff80821115612a6257612a62612a20565b604051601f8301601f19908116603f01168101908282118183101715612a8a57612a8a612a20565b81604052838152866020858801011115612aa357600080fd5b836020870160208301376000602085830101528094505050505092915050565b600080600060808486031215612ad857600080fd5b612ae184612a04565b92506060840185811115612af457600080fd5b6020850192503567ffffffffffffffff811115612b1057600080fd5b612b1c86828701612a36565b9150509250925092565b60008060408385031215612b3957600080fd5b612b4283612a04565b9150602083013567ffffffffffffffff811115612b5e57600080fd5b612b6a85828601612a36565b9150509250929050565b80516001600160a01b0316825260006101206020830151816020860152612b9d828601826128f4565b91505060408301518482036040860152612bb782826128f4565b91505060608301518482036060860152612bd182826128f4565b9150506080830151608085015260a083015160a085015260c083015160c085015260e083015184820360e0860152612c0982826128f4565b915050610100808401518583038287015261210983826128f4565b6020815260006122616020830184612b74565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b828110156129f757603f19888603018452612c7a858351612b74565b94509285019290850190600101612c5e565b600060208284031215612c9e57600080fd5b61226182612a04565b600080600060408486031215612cbc57600080fd5b612cc584612a04565b9250602084013567ffffffffffffffff80821115612ce257600080fd5b818601915086601f830112612cf657600080fd5b813581811115612d0557600080fd5b8760208260051b8501011115612d1a57600080fd5b6020830194508093505050509250925092565b60008083601f840112612d3f57600080fd5b50813567ffffffffffffffff811115612d5757600080fd5b602083019150836020828501011115612d6f57600080fd5b9250929050565b60008060008060008060008060008060e08b8d031215612d9557600080fd5b8a3567ffffffffffffffff80821115612dad57600080fd5b612db98e838f01612a36565b9b5060208d0135915080821115612dcf57600080fd5b612ddb8e838f01612a36565b9a5060408d0135915080821115612df157600080fd5b612dfd8e838f01612d2d565b909a50985060608d0135915080821115612e1657600080fd5b612e228e838f01612d2d565b909850965060808d0135915080821115612e3b57600080fd5b50612e488d828e01612d2d565b9b9e9a9d50989b979a969995989760a08101359660c09091013595509350505050565b600060208284031215612e7d57600080fd5b813567ffffffffffffffff811115612e9457600080fd5b82016080818503121561226157600080fd5b60008060408385031215612eb957600080fd5b612ec283612a04565b946020939093013593505050565b600080600060608486031215612ee557600080fd5b83359250612ef560208501612a04565b9150612f0360408501612a04565b90509250925092565b600060208284031215612f1e57600080fd5b813567ffffffffffffffff811115612f3557600080fd5b61161b84828501612a36565b600060208284031215612f5357600080fd5b5035919050565b60008060408385031215612f6d57600080fd5b612f7683612a04565b9150612f8460208401612a04565b90509250929050565b6020815260006122616020830184612920565b600181811c90821680612fb457607f821691505b602082108103612fd457634e487b7160e01b600052602260045260246000fd5b50919050565b60008251612fec8184602087016128d0565b9190910192915050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b60e08152600061303260e083018d6128f4565b8281036020840152613045818c8e612ff6565b905089604084015288606084015287608084015282810360a084015261306c818789612ff6565b905082810360c0840152613081818587612ff6565b9d9c50505050505050505050505050565b6000808335601e198436030181126130a957600080fd5b83018035915067ffffffffffffffff8211156130c457600080fd5b6020019150600581901b3603821315612d6f57600080fd5b81835260006001600160fb1b038311156130f557600080fd5b8260051b80836020870137939093016020019392505050565b6060815260006131226060830187896130dc565b82810360208401526131358186886130dc565b9150508260408301529695505050505050565b60006020828403121561315a57600080fd5b8151801515811461226157600080fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b8082018082111561135c5761135c613180565b60208152600061226160208301846128f4565b6000600182016131ce576131ce613180565b5060010190565b8181038181111561135c5761135c613180565b601f82111561201857600081815260208120601f850160051c8101602086101561320f5750805b601f850160051c820191505b81811015611aa15782815560010161321b565b815167ffffffffffffffff81111561324857613248612a20565b61325c816132568454612fa0565b846131e8565b602080601f83116001811461329157600084156132795750858301515b600019600386901b1c1916600185901b178555611aa1565b600085815260208120601f198616915b828110156132c0578886015182559484019460019091019084016132a1565b50858210156132de5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6000600160ff1b820161330357613303613180565b506000190190565b6001600160a01b038316815260406020820181905260009061161b908301846128f4565b634e487b7160e01b600052603160045260246000fdfe526824944047da5b81071fb6349412005c5da81380b336103fbe5dd34556c776a26469706673582212200be56aaec0ee2d37ceea12d1034381a3de0a1857fb059bd91f3561451861a7af64736f6c63430008140033"; - -type ServingConstructorParams = - | [signer?: Signer] - | ConstructorParameters; - -const isSuperArgs = ( - xs: ServingConstructorParams -): xs is ConstructorParameters => xs.length > 1; - -export class Serving__factory extends ContractFactory { - constructor(...args: ServingConstructorParams) { - if (isSuperArgs(args)) { - super(...args); - } else { - super(_abi, _bytecode, args[0]); - } - } - - override getDeployTransaction( - overrides?: NonPayableOverrides & { from?: string } - ): Promise { - return super.getDeployTransaction(overrides || {}); - } - override deploy(overrides?: NonPayableOverrides & { from?: string }) { - return super.deploy(overrides || {}) as Promise< - Serving & { - deploymentTransaction(): ContractTransactionResponse; - } - >; - } - override connect(runner: ContractRunner | null): Serving__factory { - return super.connect(runner) as Serving__factory; - } - - static readonly bytecode = _bytecode; - static readonly abi = _abi; - static createInterface(): ServingInterface { - return new Interface(_abi) as ServingInterface; - } - static connect(address: string, runner?: ContractRunner | null): Serving { - return new Contract(address, _abi, runner) as unknown as Serving; - } -} diff --git a/src.ts/extractor/chatbot.ts b/src.ts/extractor/chatbot.ts index 041454b..e12c110 100644 --- a/src.ts/extractor/chatbot.ts +++ b/src.ts/extractor/chatbot.ts @@ -1,15 +1,15 @@ -import { ServiceStructOutput } from '../contract/serving/Serving' +import { InferenceServiceStruct } from '../contract' import { Extractor } from './extractor' export class ChatBot extends Extractor { - svcInfo: ServiceStructOutput + svcInfo: InferenceServiceStruct - constructor(svcInfo: ServiceStructOutput) { + constructor(svcInfo: InferenceServiceStruct) { super() this.svcInfo = svcInfo } - getSvcInfo(): Promise { + getSvcInfo(): Promise { return Promise.resolve(this.svcInfo) } diff --git a/src.ts/extractor/extractor.ts b/src.ts/extractor/extractor.ts index fd339d5..703e0c3 100644 --- a/src.ts/extractor/extractor.ts +++ b/src.ts/extractor/extractor.ts @@ -1,7 +1,7 @@ -import { ServiceStructOutput } from '../contract/serving/Serving' +import { FineTuneServiceStruct, InferenceServiceStruct, ServiceStructOutput } from '../contract' export abstract class Extractor { - abstract getSvcInfo(): Promise + abstract getSvcInfo(): Promise abstract getInputCount(content: string): Promise abstract getOutputCount(content: string): Promise } diff --git a/src.ts/extractor/finetune.ts b/src.ts/extractor/finetune.ts new file mode 100644 index 0000000..885b509 --- /dev/null +++ b/src.ts/extractor/finetune.ts @@ -0,0 +1,31 @@ +import { FineTuneServiceStruct, FineTuneServingContract } from '../contract' +import { Extractor } from './extractor' + +export class ModelFineTune extends Extractor { + svcInfo: FineTuneServiceStruct + + constructor(svcInfo: FineTuneServiceStruct) { + super() + this.svcInfo = svcInfo + } + + getSvcInfo(): Promise { + return Promise.resolve(this.svcInfo) + } + + async getInputCount(content: string): Promise { + // todo: get from dataset? + if (!content) { + return 0 + } + return content.split(/\s+/).length + } + + async getOutputCount(content: string): Promise { + // todo: get from dataset? + if (!content) { + return 0 + } + return content.split(/\s+/).length + } +} diff --git a/src.ts/extractor/index.ts b/src.ts/extractor/index.ts index ab76c5d..87a9199 100644 --- a/src.ts/extractor/index.ts +++ b/src.ts/extractor/index.ts @@ -1,2 +1,3 @@ export * from './extractor' export * from './chatbot' +export * from "./finetune" diff --git a/src.ts/storage/cache.ts b/src.ts/storage/cache.ts index 702ade1..16e0990 100644 --- a/src.ts/storage/cache.ts +++ b/src.ts/storage/cache.ts @@ -1,11 +1,11 @@ -import { ServiceStructOutput } from '../contract/serving/Serving' +import { InferenceServiceStruct, FineTuneServiceStruct, QuotaStructOutput } from '../contract' +import { QuotaStruct } from '../contract/finetune/FineTuneServing' export enum CacheValueTypeEnum { - Service = 'service', + InferenceService = 'inference', + FineTuneService = 'fine-tune', } -export type CacheValueType = CacheValueTypeEnum.Service - export class Cache { private nodeStorage: { [key: string]: string } = {} private initialized = false @@ -16,7 +16,7 @@ export class Cache { key: string, value: any, ttl: number, - type: CacheValueType + type: CacheValueTypeEnum ) { await this.initialize() const now = new Date() @@ -51,13 +51,14 @@ export class Cache { this.initialized = true } + // todo: special process with quota? static encodeValue(value: any): string { return JSON.stringify(value, (_, val) => typeof val === 'bigint' ? `${val.toString()}n` : val ) } - static decodeValue(encodedValue: string, type: CacheValueType): any { + static decodeValue(encodedValue: string, type: CacheValueTypeEnum): any { let ret = JSON.parse(encodedValue, (_, val) => { if (typeof val === 'string' && /^\d+n$/.test(val)) { return BigInt(val.slice(0, -1)) @@ -65,14 +66,16 @@ export class Cache { return val }) - if (type === CacheValueTypeEnum.Service) { - return Cache.createServiceStructOutput(ret) + switch (type) { + case CacheValueTypeEnum.InferenceService: + return Cache.createInferenceServiceStruct(ret) + case CacheValueTypeEnum.FineTuneService: + return Cache.createFineTuneServiceStruct(ret) } - return ret } - static createServiceStructOutput( + static createInferenceServiceStruct( fields: [ string, string, @@ -84,7 +87,7 @@ export class Cache { string, string ] - ): ServiceStructOutput { + ): InferenceServiceStruct { const tuple: [ string, string, @@ -111,4 +114,106 @@ export class Cache { return Object.assign(tuple, object) } + + static createQuotaServiceStructOutput( + fields : [ + bigint, + bigint, + bigint, + bigint, + string, + ] + ) : QuotaStructOutput { + const tuple : [ + bigint, + bigint, + bigint, + bigint, + string, + ] = fields + + const object = { + cpuCount : fields[0], + nodeMemory : fields[1], + gpuCount : fields[2], + nodeStorage : fields[3], + gpuType : fields[4], + } + + return Object.assign(tuple, object) + } + + static createFineTuneServiceStruct( + fields: [ + // provider + string, + // name + string, + // url + string, + // quote + bigint, + bigint, + bigint, + bigint, + string, + // price per token + bigint, + // occupied + boolean + ] + ): FineTuneServiceStruct { + const q = this.createQuotaServiceStructOutput([ + fields[3], + fields[4], + fields[5], + fields[6], + fields[7], + ]) + const tuple: [ + // provider + string, + // name + string, + // url + string, + QuotaStructOutput, + // quote + // bigint, + // bigint, + // bigint, + // bigint, + // string, + // price per token + bigint, + // occupied + boolean + ] = [ + fields[0] , + fields[1] , + fields[2] , + q, + fields[8], + fields[9] + ] + // + // const quota_object = { + // quota_cpuCount: fields[3], + // quota_nodeMemory: fields[4], + // quota_gpuCount: fields[5], + // quota_nodeStorage: fields[6], + // quota_gpuType: fields[7], + // } + // const quota = Object.assign(tuple, quota_object) + + const object = { + provider: fields[0], + name: fields[1], + url: fields[2], + quota : q, + pricePerToken: fields[8], + occupied : fields[9] + } + return Object.assign(tuple, object) + } } diff --git a/tests/finetune.ts b/tests/finetune.ts new file mode 100644 index 0000000..346245a --- /dev/null +++ b/tests/finetune.ts @@ -0,0 +1,19 @@ + +// @ts-ignore +import {createZGServingNetworkBroker} from '../src.ts/broker' +import { ethers } from 'ethers' + +async function main() { + const provider = new ethers.JsonRpcProvider('https://evmrpc-testnet.0g.ai') + const privateKey = + '1A6338193E6C204381E6C68BB0F60DC1B83418D7C9B5C928C4FB99E917702261' + const wallet = new ethers.Wallet(privateKey, provider) + + try { + const broker = createZGServingNetworkBroker(wallet) + const services = await broker.listService() + + + } + +} diff --git a/tests/inference.ts b/tests/inference.ts new file mode 100644 index 0000000..e69de29