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

cdp e mode toggle + calculations #282

Open
wants to merge 9 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions scripts/generate-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ console.log(`import { Registry } from "@cosmjs/proto-signing";`);
console.log(`import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";`);

const modules: { [name: string]: string[] } = {};
const currentMsgDefinitions: string[] = []
// TODO: To remove hardcode conditional once a better way to fix MsgSend import is found
const currentMsgDefinitions: string[] = ['MsgSend', 'MsgSendResponse']
for (const moduleFile of codecFiles) {

if (
Expand Down Expand Up @@ -89,7 +90,10 @@ const typeMap: { [msg: string]: string } = {};
for (const packageName in modules) {
console.log("");
for (const key of modules[packageName]) {
const messageAlias = key.split(" ")[2] // "XXX as XXXXX"
let messageAlias = key.split(" ")[2] // "XXX as XXXXX"
// if (messageAlias && messageAlias.includes("MsgBankSend")) {
// messageAlias = ''
// }
const typeUrl = messageAlias ? `/${packageName}.${key.split(" ")[0].trim()}` : `/${packageName}.${key}`;
const messageType = messageAlias ? messageAlias.trim() : key
typeMap[messageType] = typeUrl;
Expand Down Expand Up @@ -181,9 +185,17 @@ function updateImportsAlias(messages: string[], protobufPackage: string, current
let msgAlias = `Msg${customModuleName}${msg.substring(3)}`
while (currentMsgDefinitions.includes(msgAlias) && index < modulePath.length) {
customModuleName += capitalize(modulePath[index])
msgAlias = `Msg${customModuleName}${msg.substring(3)}`
msgAlias = `Msg${customModuleName}${msg.substring(3)}`
index++
}
// TODO: To remove hardcode conditional once a better way to remove alias for MsgBankSend is found
if (
msg === 'MsgSend' && msgAlias === 'MsgBankSend' ||
msg === 'MsgSendResponse' && msgAlias === 'MsgBankSendResponse'
) {
currentMsgDefinitions.push(msg)
return
}
messages[i] = `${msg} as ${msgAlias}`
currentMsgDefinitions.push(msgAlias)
});
Expand Down
166 changes: 166 additions & 0 deletions src/codec/cdp/e_mode_category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal";

export const protobufPackage = "Switcheo.carbon.cdp";

export interface EModeCategory {
name: string;
denoms: string[];
loanToValue: string;
liquidationThreshold: string;
liquidationDiscount: string;
isActive: boolean;
}

const baseEModeCategory: object = {
name: "",
denoms: "",
loanToValue: "",
liquidationThreshold: "",
liquidationDiscount: "",
isActive: false,
};

export const EModeCategory = {
encode(
message: EModeCategory,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.name !== "") {
writer.uint32(10).string(message.name);
}
for (const v of message.denoms) {
writer.uint32(18).string(v!);
}
if (message.loanToValue !== "") {
writer.uint32(26).string(message.loanToValue);
}
if (message.liquidationThreshold !== "") {
writer.uint32(34).string(message.liquidationThreshold);
}
if (message.liquidationDiscount !== "") {
writer.uint32(42).string(message.liquidationDiscount);
}
if (message.isActive === true) {
writer.uint32(48).bool(message.isActive);
}
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): EModeCategory {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = { ...baseEModeCategory } as EModeCategory;
message.denoms = [];
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.name = reader.string();
break;
case 2:
message.denoms.push(reader.string());
break;
case 3:
message.loanToValue = reader.string();
break;
case 4:
message.liquidationThreshold = reader.string();
break;
case 5:
message.liquidationDiscount = reader.string();
break;
case 6:
message.isActive = reader.bool();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},

fromJSON(object: any): EModeCategory {
const message = { ...baseEModeCategory } as EModeCategory;
message.name =
object.name !== undefined && object.name !== null
? String(object.name)
: "";
message.denoms = (object.denoms ?? []).map((e: any) => String(e));
message.loanToValue =
object.loanToValue !== undefined && object.loanToValue !== null
? String(object.loanToValue)
: "";
message.liquidationThreshold =
object.liquidationThreshold !== undefined &&
object.liquidationThreshold !== null
? String(object.liquidationThreshold)
: "";
message.liquidationDiscount =
object.liquidationDiscount !== undefined &&
object.liquidationDiscount !== null
? String(object.liquidationDiscount)
: "";
message.isActive =
object.isActive !== undefined && object.isActive !== null
? Boolean(object.isActive)
: false;
return message;
},

toJSON(message: EModeCategory): unknown {
const obj: any = {};
message.name !== undefined && (obj.name = message.name);
if (message.denoms) {
obj.denoms = message.denoms.map((e) => e);
} else {
obj.denoms = [];
}
message.loanToValue !== undefined &&
(obj.loanToValue = message.loanToValue);
message.liquidationThreshold !== undefined &&
(obj.liquidationThreshold = message.liquidationThreshold);
message.liquidationDiscount !== undefined &&
(obj.liquidationDiscount = message.liquidationDiscount);
message.isActive !== undefined && (obj.isActive = message.isActive);
return obj;
},

fromPartial(object: DeepPartial<EModeCategory>): EModeCategory {
const message = { ...baseEModeCategory } as EModeCategory;
message.name = object.name ?? "";
message.denoms = (object.denoms ?? []).map((e) => e);
message.loanToValue = object.loanToValue ?? "";
message.liquidationThreshold = object.liquidationThreshold ?? "";
message.liquidationDiscount = object.liquidationDiscount ?? "";
message.isActive = object.isActive ?? false;
return message;
},
};

type Builtin =
| Date
| Function
| Uint8Array
| string
| number
| boolean
| undefined;
export type DeepPartial<T> = T extends Builtin
? T
: T extends Long
? string | number | Long
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
}
Loading