Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cache / expire uAgent almanac resolutions #198

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ enum Interface {
Uncertain,
CW20,
LegacyBridgeSwap,
MicroAgentAlmanac,
}

enum AccessType {
Expand Down
4 changes: 2 additions & 2 deletions src/mappings/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {createHash} from "crypto";
import {Attribute} from "@cosmjs/stargate/build/logs";
import {LegacyBridgeSwapStructure} from "./wasm/contracts/bridge";
import {CW20Structure} from "./wasm/contracts/cw20";
import {Structure} from "./wasm/contracts/types";
import {BaseStructure} from "./wasm/contracts/base";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should've been in d7c166f, my bad.

import {MicroAgentAlmanacStructure} from "./wasm/contracts/almanac";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was supposed to be in d7c166f


export type Primitive = CosmosEvent | CosmosMessage | CosmosTransaction | CosmosBlock;
Expand All @@ -31,7 +31,7 @@ export async function checkBalancesAccount(address: string, chainId: string) {
}

export function getJaccardResult(payload: object): Interface {
let prediction = Structure, prediction_coefficient = 0.5; // prediction coefficient can be set as a minimum threshold for the certainty of an output
let prediction = BaseStructure, prediction_coefficient = 0.5; // prediction coefficient can be set as a minimum threshold for the certainty of an output
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same ^

let diff = 0, match = 0, coefficient = 0; // where coefficient of 1 is a perfect property key match, 2 is a perfect match of property and type
// TODO: refactor
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more maintainable if we redesigned this a little bit. Perhaps we can add a contract structure registry which this function iterates over (as opposed to a hard-coded list of known structures). Each structure would import the registry and register itself. I suspect that the index (i.e. src/mappings/wasm/contracts) would have to be required (import value ignored) just so that they are included in the build tree (and their registration calls get run, subsequently). Effort may need to be taken to avoid circular dependencies when building and bootstrapping the registry. I think so long as the contract structure index isn't in the same module as the registry we should be good. I would imagine a good place for this import would be in the src/mappings/mappingHandler.ts file instead.

const structs = [CW20Structure, LegacyBridgeSwapStructure, MicroAgentAlmanacStructure];
Expand Down
21 changes: 21 additions & 0 deletions src/mappings/wasm/contracts/almanac.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {BaseStructure} from "./base";
import {Interface} from "../../../types";

export class MicroAgentAlmanacStructure extends BaseStructure {
private stake_denom = "";
private expiry_height = 0;
private register_stake_amount = "0";
private admin = "";

static listProperties() {
return Object.getOwnPropertyNames(new MicroAgentAlmanacStructure());
}

static getPropertyType(prop: string) {
return typeof (new MicroAgentAlmanacStructure()[prop]);
}

static getInterface() {
return Interface.MicroAgentAlmanac;
}
}
2 changes: 1 addition & 1 deletion tests/e2e/entities/test_almanac.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def sql_by_expiry_height(registration_row: Tuple) -> int:
class Scenario:
name: str
query: graphql.DocumentNode
expected: Any
expected: any


class TestAlmanac(EntityTest):
Expand Down