Skip to content

Commit

Permalink
Merge pull request #84 from terra-money/feat/smartaccs
Browse files Browse the repository at this point in the history
Feat/smartaccs
  • Loading branch information
emidev98 authored Mar 14, 2024
2 parents d07a6ba + 8b82d38 commit 5866dc3
Show file tree
Hide file tree
Showing 19 changed files with 1,034 additions and 18 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@terra-money/feather.js",
"version": "3.0.0-beta.0",
"version": "3.0.0-beta.1",
"description": "The JavaScript SDK for Terra and Feather chains",
"license": "MIT",
"author": "Terraform Labs, PTE.",
Expand Down Expand Up @@ -86,7 +86,7 @@
},
"dependencies": {
"@terra-money/legacy.proto": "npm:@terra-money/terra.proto@^0.1.7",
"@terra-money/terra.proto": "5.2.0",
"@terra-money/terra.proto": "5.3.0-beta.0",
"assert": "^2.0.0",
"axios": "^0.27.2",
"bech32": "^2.0.0",
Expand Down
5 changes: 4 additions & 1 deletion src/client/lcd/LCDClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
IbcTransferAPI,
IbcAPI,
TokenFactory,
FeemarketAPI,
SmartaccountAPI,
} from './api';
import { LCDUtils } from './LCDUtils';
import { Wallet } from './Wallet';
Expand All @@ -27,7 +29,6 @@ import { FeeshareAPI } from './api/FeeshareAPI';
import { GovV1API } from './api/GovV1API';
import { ICAv1API } from './api/ICAv1API';
import { ICQv1API } from './api/ICQv1API';
import { FeemarketAPI } from './api/FeemarketAPI';

export type AxiosConfig = {
/**
Expand Down Expand Up @@ -138,6 +139,7 @@ export class LCDClient {
public feeshare: FeeshareAPI;
public feemarket: FeemarketAPI;
public utils: LCDUtils;
public smartaccount: SmartaccountAPI;

/**
* Creates a new LCD client with the specified configuration.
Expand Down Expand Up @@ -189,6 +191,7 @@ export class LCDClient {
this.feeshare = new FeeshareAPI(this);
this.feemarket = new FeemarketAPI(this);
this.utils = new LCDUtils(this);
this.smartaccount = new SmartaccountAPI(this);
}

public static fromDefaultConfig(network: 'mainnet' | 'testnet') {
Expand Down
10 changes: 5 additions & 5 deletions src/client/lcd/api/AllianceAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class AllianceAPI extends BaseAPI {
}

// If all parameters are provided, the response will be a single delegation.
// In order to fit the return type, an array of delegations is returned.
// In order to fit the return type, an array of delegations is returned.
if (delAddr && valAddr && denom) {
const res = await this.getReqFromChainID(chainID).get<{
delegation: AllianceDelegation.Data;
Expand Down Expand Up @@ -232,9 +232,9 @@ export class AllianceAPI extends BaseAPI {
* that valAddr depend on the denom. When all values are provided the query will be faster,
* Any denom specified in this query will be URL encoded to allow querying for alliance assets
* with "/" or other special characters in their denom.
*
*
* - When **delAddr** is provided, this query returns the unbondings for the provided address.
* - When **denom** and **delAddr** are provided, this query returns the unbondings for the
* - When **denom** and **delAddr** are provided, this query returns the unbondings for the
* specified address and denom.
* - When **delAddr**, **valAddr** and **denom** are provided, this query returns the unbondings
* for the specified address, validator and denom.
Expand Down Expand Up @@ -274,8 +274,8 @@ export class AllianceAPI extends BaseAPI {
}

/**
* Query all validators that have at least one user delegation. You can optionally provide valAddr
* to query a single validator. Providing the validatorAddr will deliver a faster response.
* Query all validators that have at least one user delegation. You can optionally provide valAddr
* to query a single validator. Providing the validatorAddr will deliver a faster response.
* This query returns data about the delegations shares, validator shares,
* and total staked tokens.
*
Expand Down
File renamed without changes.
41 changes: 41 additions & 0 deletions src/client/lcd/api/SmartaccountAPI.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Setting } from '../../../core/smartaccount/v1/models/Setting';

Check warning on line 1 in src/client/lcd/api/SmartaccountAPI.spec.ts

View workflow job for this annotation

GitHub Actions / build

'Setting' is defined but never used
import { SmartaccountParams } from '../../../core/smartaccount/v1/models/SmartaccountParams';
import { LCDClient } from '../LCDClient';
import { SmartaccountAPI } from './SmartaccountAPI';

const lcd = new LCDClient({
'pisco-1': {
chainID: 'pisco-1',
gasAdjustment: 1.5,
gasPrices: {
uluna: 0.02,
},
lcd: 'http://localhost:1317/',
prefix: 'terra',
},
});
const smartaccount = new SmartaccountAPI(lcd);

describe('SmartaccountAPI', () => {
it('assert the module params', async () => {
const res = await smartaccount.params('pisco-1');

expect(res).toStrictEqual(new SmartaccountParams());

expect(res.toData()).toEqual({});
});

// test with wallet15 terra1tck9vx8vwu6l83zy76ssdkhnhw8dfcrt80hc6x
it('assert the account setting', async () => {
const res = await smartaccount.setting(
'terra1tck9vx8vwu6l83zy76ssdkhnhw8dfcrt80hc6x'
);
expect(res.toData()).toEqual({
owner: 'terra1tck9vx8vwu6l83zy76ssdkhnhw8dfcrt80hc6x',
authorization: [],
post_transaction: [],
pre_transaction: [],
fallback: true,
});
});
});
41 changes: 41 additions & 0 deletions src/client/lcd/api/SmartaccountAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Setting } from '../../../core/smartaccount';
import { AccAddress } from '../../../core';
import { LCDClient } from '../LCDClient';
import { BaseAPI } from './BaseAPI';
import { SmartaccountParams } from '../../../core/smartaccount';

export class SmartaccountAPI extends BaseAPI {
constructor(public lcd: LCDClient) {
super(lcd.apiRequesters, lcd.config);
}

/**
* Query the feemarket module params.
*
* @tags Query
* @name params
* @request GET:/terra/smartaccount/v1/params
*/
public async params(chainId: string): Promise<SmartaccountParams> {
const res = await this.getReqFromChainID(chainId).get<{
params: SmartaccountParams.Data;
}>(`/terra/smartaccount/v1/params`);

return SmartaccountParams.fromData(res.params);
}

/**
* Query the feemarket module setting for account.
*
* @tags Query
* @name setting
* @request GET:/terra/smartaccount/v1/setting/{account}
*/
public async setting(account: AccAddress): Promise<Setting> {
const res = await this.getReqFromAddress(account).get<{
setting: Setting.Data;
}>(`/terra/smartaccount/v1/setting/${account}`);

return Setting.fromData(res.setting);
}
}
2 changes: 2 additions & 0 deletions src/client/lcd/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export * from './MintAPI';
export * from './TokenFactoryAPI';
export * from './IbcAPI';
export * from './IbcTransferAPI';
export * from './FeemarketAPI';
export * from './SmartaccountAPI';
57 changes: 53 additions & 4 deletions src/core/Msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ import {
} from './ica/controller/v1/msgs';
import { MsgForceTransfer } from './tokenfactory/MsgForceTransfer';
import { MsgSetDenomMetadata } from './tokenfactory/MsgSetDenomMetadata';
import {
MsgCreateSmartAccount,
MsgDisableSmartAccount,
MsgUpdateAuthorization,
MsgUpdateTransactionHooks,
SmartAccountMsg,
} from './smartaccount';

export type Msg =
| BankMsg
Expand All @@ -143,7 +150,8 @@ export type Msg =
| CrisisMsg
| MsgAuctionBid
| FeeshareMsg
| TokenFactoryMsg;
| TokenFactoryMsg
| SmartAccountMsg;

export namespace Msg {
export type Amino =
Expand All @@ -163,7 +171,8 @@ export namespace Msg {
| CrisisMsg.Amino
| MsgAuctionBid.Amino
| FeeshareMsg.Amino
| TokenFactoryMsg.Amino;
| TokenFactoryMsg.Amino
| SmartAccountMsg.Amino;

export type Data =
| BankMsg.Data
Expand All @@ -186,7 +195,8 @@ export namespace Msg {
| CrisisMsg.Data
| MsgAuctionBid.Data
| FeeshareMsg.Data
| TokenFactoryMsg.Data;
| TokenFactoryMsg.Data
| SmartAccountMsg.Data;

export type Proto =
| BankMsg.Proto
Expand All @@ -208,7 +218,8 @@ export namespace Msg {
| CrisisMsg.Proto
| MsgAuctionBid.Proto
| FeeshareMsg.Proto
| TokenFactoryMsg.Proto;
| TokenFactoryMsg.Proto
| SmartAccountMsg.Proto;

export function fromAmino(data: Msg.Amino, isClassic?: boolean): Msg {
switch (data.type) {
Expand Down Expand Up @@ -501,6 +512,24 @@ export namespace Msg {
isClassic
);

// SmartAccount module
case 'terra/MsgCreateSmartAccount':
return MsgCreateSmartAccount.fromAmino(
data as MsgCreateSmartAccount.Amino
);
case 'terra/MsgDisableSmartAccount':
return MsgDisableSmartAccount.fromAmino(
data as MsgDisableSmartAccount.Amino
);
case 'terra/MsgUpdateAuthorization':
return MsgUpdateAuthorization.fromAmino(
data as MsgUpdateAuthorization.Amino
);
case 'terra/MsgUpdateTransactionHooks':
return MsgUpdateTransactionHooks.fromAmino(
data as MsgUpdateTransactionHooks.Amino
);

// custom
default:
return MsgAminoCustom.fromAmino(data as any, isClassic);
Expand Down Expand Up @@ -703,6 +732,16 @@ export namespace Msg {
case '/juno.feeshare.v1.MsgCancelFeeShare':
return MsgCancelFeeShare.fromData(data, isClassic);

// SmartAccount
case '/terra.smartaccount.v1.MsgCreateSmartAccount':
return MsgCreateSmartAccount.fromData(data);
case '/terra.smartaccount.v1.MsgDisableSmartAccount':
return MsgDisableSmartAccount.fromData(data);
case '/terra.smartaccount.v1.MsgUpdateAuthorization':
return MsgUpdateAuthorization.fromData(data);
case '/terra.smartaccount.v1.MsgUpdateTransactionHooks':
return MsgUpdateTransactionHooks.fromData(data);

// custom
default:
return MsgAminoCustom.fromData(data as any, isClassic);
Expand Down Expand Up @@ -908,6 +947,16 @@ export namespace Msg {
case '/juno.feeshare.v1.MsgCancelFeeShare':
return MsgCancelFeeShare.unpackAny(proto, isClassic);

// SmartAccount
case '/terra.smartaccount.v1.MsgCreateSmartAccount':
return MsgCreateSmartAccount.unpackAny(proto);
case '/terra.smartaccount.v1.MsgDisableSmartAccount':
return MsgDisableSmartAccount.unpackAny(proto);
case '/terra.smartaccount.v1.MsgUpdateAuthorization':
return MsgUpdateAuthorization.unpackAny(proto);
case '/terra.smartaccount.v1.MsgUpdateTransactionHooks':
return MsgUpdateTransactionHooks.unpackAny(proto);

default:
throw Error(`not supported msg ${proto.typeUrl}`);
}
Expand Down
5 changes: 5 additions & 0 deletions src/core/smartaccount/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './v1/msgs';
export * from './v1/models/Initialization';
export * from './v1/models/AuthorizationMsg';
export * from './v1/models/Setting';
export * from './v1/models/SmartaccountParams';
Loading

0 comments on commit 5866dc3

Please sign in to comment.