Skip to content

Commit

Permalink
wip: feat(cw): namada decodeInner, pt.6
Browse files Browse the repository at this point in the history
  • Loading branch information
egasimus committed Mar 7, 2024
1 parent 4299cdc commit e94fca1
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 157 deletions.
4 changes: 1 addition & 3 deletions packages/cw/namada/namada-address.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Core } from '@fadroma/agent'
import * as Borsher from 'borsher'
import { schemaEnum } from './namada-enum'

const Schema = Borsher.BorshSchema
import { Schema, schemaEnum } from './namada-types'

export const InternalAddresses = {
Governance: "tnam1q5qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqrw33g6"
Expand Down
18 changes: 0 additions & 18 deletions packages/cw/namada/namada-enum.ts

This file was deleted.

19 changes: 13 additions & 6 deletions packages/cw/namada/namada-gov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { Core } from '@fadroma/agent'
import type { Address } from '@fadroma/agent'
import type { Address as NamadaAddress } from './namada-address'
import { addressSchema, InternalAddresses, decodeAddressFields } from './namada-address'
import { u256Schema, decodeU256Fields } from './namada-u256'
import { fromBorshStruct } from './namada-struct'
import {
Schema, fromBorshStruct, schemaEnum, enumVariant, u256Schema, decodeU256Fields
} from './namada-types'

type Connection = { abciQuery: (path: string)=>Promise<Uint8Array> }

const Schema = Borsher.BorshSchema

export async function getGovernanceParameters (connection: Connection) {
const binary = await connection.abciQuery(`/vp/governance/parameters`)
return GovernanceParameters.fromBorsh(binary) as GovernanceParameters
Expand Down Expand Up @@ -215,6 +214,14 @@ export class ProposalResult extends fromBorshStruct({
}
}

export class InitProposal extends fromBorshStruct({}) {}
export class InitProposal extends fromBorshStruct({}) {
print (console) {
throw new Error('print InitProposal: not implemented')
}
}

export class VoteProposal extends fromBorshStruct({}) {}
export class VoteProposal extends fromBorshStruct({}) {
print (console) {
throw new Error('print VoteProposal: not implemented')
}
}
Empty file removed packages/cw/namada/namada-ibc.ts
Empty file.
18 changes: 12 additions & 6 deletions packages/cw/namada/namada-pgf.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import type { Address } from './namada-address'
import { addressSchema } from './namada-address'
import { u256Schema, decodeU256Fields } from './namada-u256'
import { Core } from '@fadroma/agent'
import * as Borsher from 'borsher'
import { fromBorshStruct } from './namada-struct'
const Schema = Borsher.BorshSchema
import type { Address } from './namada-address'
import { addressSchema } from './namada-address'
import {
Schema,
fromBorshStruct,
schemaEnum,
enumVariant,
u256Schema,
i256Schema,
decodeU256Fields
} from './namada-types'

type Connection = { abciQuery: (path: string)=>Promise<Uint8Array> }

Expand Down Expand Up @@ -48,7 +54,7 @@ export async function isPGFSteward (connection: Connection) {

export class UpdateStewardCommission extends fromBorshStruct({
steward: addressSchema,
commission: Schema.HashMap(addressSchema, Dec)
commission: Schema.HashMap(addressSchema, i256Schema)
}) {
steward: Address
commission: Map<string, bigint>
Expand Down
38 changes: 21 additions & 17 deletions packages/cw/namada/namada-pos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import type { Address } from '@fadroma/agent'
import { Core } from '@fadroma/agent'
import { addressSchema, InternalAddresses, decodeAddress } from './namada-address'
import type { Address as NamadaAddress } from './namada-address'
import { u256Schema, decodeU256, decodeU256Fields } from './namada-u256'
import { schemaEnum } from './namada-enum'
import {
Schema,
fromBorshStruct,
schemaEnum,
u256Schema,
i256Schema,
decodeU256,
decodeU256Fields
} from './namada-types'
import type { NamadaConnection } from './namada-connection'
import { fromBorshStruct } from './namada-struct'
import * as Staking from '../cw-staking'

const Schema = Borsher.BorshSchema

export async function getStakingParameters (connection: NamadaConnection) {
const binary = await connection.abciQuery("/vp/pos/pos_params")
return PosParams.fromBorsh(binary)
Expand Down Expand Up @@ -269,19 +273,19 @@ const stateSchema = Schema.Option(schemaEnum([

const stakeSchema = Schema.Option(u256Schema)

const consensusKeySchema = Schema.Option(schemaEnum([
const publicKeySchema = Schema.Option(schemaEnum([
['Ed25519', Schema.Array(Schema.u8, 32)],
['Secp256k1', Schema.Array(Schema.u8, 33)],
]))

export class BecomeValidator extends fromBorshStruct({
address: addressSchema,
consensus_key: PublicKey,
eth_cold_key: PublicKey,
eth_hot_key: PublicKey,
protocol_key: PublicKey,
commission_rate: Dec,
max_commission_rate_change: Dec,
consensus_key: publicKeySchema,
eth_cold_key: publicKeySchema,
eth_hot_key: publicKeySchema,
protocol_key: publicKeySchema,
commission_rate: u256Schema,
max_commission_rate_change: u256Schema,
email: Schema.String,
description: Schema.Option(Schema.String),
website: Schema.Option(Schema.String),
Expand All @@ -304,7 +308,7 @@ export class BecomeValidator extends fromBorshStruct({

export class Bond extends fromBorshStruct({
validator: addressSchema,
amount: Amount,
amount: u256Schema,
source: Schema.Option(addressSchema)
}) {
validator: Address
Expand All @@ -325,12 +329,12 @@ export class ConsensusKeyChange extends fromBorshStruct({
consensus_key: publicKeySchema,
}) {
validator: Address
consensusKey: PublicKey
consensusKey: unknown
}

export class CommissionChange extends fromBorshStruct({
validator: addressSchema,
new_rate: Dec
new_rate: i256Schema
}) {
validator: Address
newRate: bigint
Expand All @@ -343,7 +347,7 @@ export class MetaDataChange extends fromBorshStruct({
website: Schema.Option(Schema.String),
discord_handle: Schema.Option(Schema.String),
avatar: Schema.Option(Schema.String),
commission_rate: Schema.Option(Dec),
commission_rate: Schema.Option(i256Schema),
}) {
validator: Address
email: null|string
Expand All @@ -358,7 +362,7 @@ export class Redelegation extends fromBorshStruct({
src_validator: addressSchema,
dest_validator: addressSchema,
owner: addressSchema,
amount: Amount
amount: i256Schema
}) {
srcValidator: Address
destValidator: Address
Expand Down
17 changes: 0 additions & 17 deletions packages/cw/namada/namada-struct.ts

This file was deleted.

Empty file.
50 changes: 0 additions & 50 deletions packages/cw/namada/namada-tx-inner.ts

This file was deleted.

57 changes: 45 additions & 12 deletions packages/cw/namada/namada-tx.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Core } from '@fadroma/agent'
import * as Borsher from 'borsher'
import { schemaEnum, enumVariant } from './namada-enum'
import {
Schema,
fromBorshStruct,
schemaEnum,
enumVariant,
u256Schema,
i256Schema
} from './namada-types'
import { addressSchema, decodeAddress } from './namada-address'
import { u256Schema } from './namada-u256'
import { fromBorshStruct } from './namada-struct'
import {
BecomeValidator,
Bond,
Expand All @@ -27,8 +32,6 @@ import {
VoteProposal
} from './namada-gov'

const Schema = Borsher.BorshSchema

const hashSchema = Schema.Array(Schema.u8, 32)

const publicKeySchema = schemaEnum([
Expand Down Expand Up @@ -701,22 +704,36 @@ export class InitAccount extends fromBorshStruct({
publicKeys
vpCodeHash
threshold
print (console) {
throw new Error('print InitAccount: not implemented')
}
}

export class UpdateAccount extends fromBorshStruct({
addr: addressSchema,
vp_code_hash: Schema.Option(Schema.Array(Schema.u8, 32)),
public_keys: Schema.Vec(publicKeySchema),
threshold: Schema.Option(Schema.u8)
}) {}
}) {
print (console) {
throw new Error('print UpdateAccount: not implemented')
}
}

export class RevealPK extends fromBorshStruct({}) {}
export class RevealPK extends fromBorshStruct({}) {
print (console) {
throw new Error('print RevealPK: not implemented')
}
}

export class Transfer extends fromBorshStruct({
source: addressSchema,
target: addressSchema,
token: addressSchema,
amount: denominatedAmountSchema,
amount: Schema.Struct({
amount: i256Schema,
denom: Schema.u8
}),
key: Schema.Option(Schema.String),
shielded: Schema.Option(Schema.Array(Schema.u8, 32))
}) {
Expand All @@ -728,10 +745,26 @@ export class Transfer extends fromBorshStruct({
shielded
}

export class VPImplicit extends fromBorshStruct({}) {}
export class VPImplicit extends fromBorshStruct({}) {
print (console) {
throw new Error('print VPImplicit: not implemented')
}
}

export class VPUser extends fromBorshStruct({}) {}
export class VPUser extends fromBorshStruct({}) {
print (console) {
throw new Error('print VPUser: not implemented')
}
}

export class BridgePool extends fromBorshStruct({}) {}
export class BridgePool extends fromBorshStruct({}) {
print (console) {
throw new Error('print BridgePool: not implemented')
}
}

export class IBC extends fromBorshStruct({}) {}
export class IBC extends fromBorshStruct({}) {
print (console) {
throw new Error('print IBC: not implemented')
}
}
Loading

0 comments on commit e94fca1

Please sign in to comment.