Skip to content

Commit

Permalink
Merge pull request #133 from Agoric/main
Browse files Browse the repository at this point in the history
Deploy 'main' to production
  • Loading branch information
samsiegart authored Dec 27, 2023
2 parents 0ac53c2 + 967393d commit 069daae
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 52 deletions.
2 changes: 1 addition & 1 deletion wallet/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ module.exports = {
},
],
},
ignorePatterns: ['**/*.umd.js', '**/generated/*'],
ignorePatterns: ['**/*.umd.js', '**/generated/*', '**/*.d.ts'],
};
6 changes: 5 additions & 1 deletion wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
"@agoric/smart-wallet": "^0.5.4-dev-6bce049.0",
"@agoric/ui-components": "^0.3.9-dev-2c6fbc5.0",
"@agoric/web-components": "^0.6.4-dev-2c6fbc5.0",
"@cosmjs/amino": "^0.31.1",
"@cosmjs/crypto": "^0.31.1",
"@cosmjs/encoding": "^0.31.1",
"@cosmjs/math": "^0.31.1",
"@cosmjs/proto-signing": "^0.31.1",
"@cosmjs/stargate": "^0.31.1",
"@cosmjs/tendermint-rpc": "^0.31.1",
"@cosmjs/utils": "^0.31.1",
"@emotion/react": "^11.5.0",
"@emotion/styled": "^11.3.0",
"@endo/captp": "^3.1.1",
Expand All @@ -42,6 +45,7 @@
"react-dom": "^16.8.0",
"react-router-dom": "^5.3.0",
"ses": "^0.18.1",
"stridejs": "^0.6.2",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down Expand Up @@ -199,4 +203,4 @@
"publishConfig": {
"access": "public"
}
}
}
4 changes: 4 additions & 0 deletions wallet/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module 'stridejs/module/codegen/stride/vesting/vesting' {
import { StridePeriodicVestingAccount } from 'stridejs/types/codegen/stride/vesting/vesting';
export { StridePeriodicVestingAccount };
}
105 changes: 105 additions & 0 deletions wallet/src/util/accountParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { Pubkey } from '@cosmjs/amino';
import { Uint64 } from '@cosmjs/math';
import { decodePubkey } from '@cosmjs/proto-signing';
import { assert } from '@cosmjs/utils';
import {
BaseAccount,
ModuleAccount,
} from 'cosmjs-types/cosmos/auth/v1beta1/auth';
import {
BaseVestingAccount,
ContinuousVestingAccount,
DelayedVestingAccount,
PeriodicVestingAccount,
} from 'cosmjs-types/cosmos/vesting/v1beta1/vesting';
import { Any } from 'cosmjs-types/google/protobuf/any';
import { StridePeriodicVestingAccount } from 'stridejs/main/codegen/stride/vesting/vesting';

export interface Account {
/** Bech32 account address */
readonly address: string;
readonly pubkey: Pubkey | null;
readonly accountNumber: number;
readonly sequence: number;
}

function uint64FromProto(input: number | bigint): Uint64 {
return Uint64.fromString(input.toString());
}

function accountFromBaseAccount(input: BaseAccount): Account {
const { address, pubKey, accountNumber, sequence } = input;
const pubkey = pubKey ? decodePubkey(pubKey) : null;
return {
address: address,
pubkey: pubkey,
accountNumber: uint64FromProto(accountNumber).toNumber(),
sequence: uint64FromProto(sequence).toNumber(),
};
}

/**
* Represents a generic function that takes an `Any` encoded account from the chain
* and extracts some common `Account` information from it.
*/
export type AccountParser = (any: Any) => Account;

/**
* Basic implementation of AccountParser. This is supposed to support the most relevant
* common Cosmos SDK account types. If you need support for exotic account types,
* you'll need to write your own account decoder.
*/
export function accountFromAny(input: Any): Account {
const { typeUrl, value } = input;

switch (typeUrl) {
// auth

case '/cosmos.auth.v1beta1.BaseAccount':
return accountFromBaseAccount(BaseAccount.decode(value));
case '/cosmos.auth.v1beta1.ModuleAccount': {
const baseAccount = ModuleAccount.decode(value).baseAccount;
assert(baseAccount);
return accountFromBaseAccount(baseAccount);
}

// vesting

case '/cosmos.vesting.v1beta1.BaseVestingAccount': {
const baseAccount = BaseVestingAccount.decode(value)?.baseAccount;
assert(baseAccount);
return accountFromBaseAccount(baseAccount);
}
case '/cosmos.vesting.v1beta1.ContinuousVestingAccount': {
const baseAccount =
ContinuousVestingAccount.decode(value)?.baseVestingAccount?.baseAccount;
assert(baseAccount);
return accountFromBaseAccount(baseAccount);
}
case '/cosmos.vesting.v1beta1.DelayedVestingAccount': {
const baseAccount =
DelayedVestingAccount.decode(value)?.baseVestingAccount?.baseAccount;
assert(baseAccount);
return accountFromBaseAccount(baseAccount);
}
case '/cosmos.vesting.v1beta1.PeriodicVestingAccount': {
const baseAccount =
PeriodicVestingAccount.decode(value)?.baseVestingAccount?.baseAccount;
assert(baseAccount);
return accountFromBaseAccount(baseAccount);
}

// custom

case '/stride.vesting.StridePeriodicVestingAccount': {
const baseAccount =
StridePeriodicVestingAccount.decode(value).baseVestingAccount
.baseAccount;
assert(baseAccount);
return accountFromBaseAccount(baseAccount);
}

default:
throw new Error(`Unsupported type: '${typeUrl}'`);
}
}
5 changes: 4 additions & 1 deletion wallet/src/util/ibcTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SigningStargateClient } from '@cosmjs/stargate';
import { AssetInfo } from './ibc-assets';
import { KnownNetworkConfigUrls } from './connections';
import { fetchChainInfo } from './chainInfo';
import { accountFromAny } from './accountParser';

const secondsUntilTimeout = 300;

Expand All @@ -23,7 +24,9 @@ export const sendIbcTokens = async (
) => {
const { sourceChannel, sourcePort, denom } = assetInfo;

const client = await SigningStargateClient.connectWithSigner(rpc, signer);
const client = await SigningStargateClient.connectWithSigner(rpc, signer, {
accountParser: accountFromAny,
});

return client.sendIbcTokens(
from,
Expand Down
2 changes: 2 additions & 0 deletions wallet/src/util/keyManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {

import { stableCurrency, bech32Config } from './chainInfo';
import type { ChainInfo, Keplr } from '@keplr-wallet/types';
import { accountFromAny } from './accountParser';

export function toAccAddress(address: string): Uint8Array {
return fromBech32(address).data;
Expand Down Expand Up @@ -403,6 +404,7 @@ export const makeInteractiveSigner = async (
const signingClient = await connectWithSigner(chainInfo.rpc, offlineSigner, {
aminoTypes: new AminoTypes(converters),
registry: SwingsetRegistry,
accountParser: accountFromAny,
});
console.debug('InteractiveSigner', { signingClient });

Expand Down
Loading

0 comments on commit 069daae

Please sign in to comment.