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: feemarket #82

Merged
merged 23 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
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": "2.0.4",
"version": "2.1.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": "^4.0.4",
"@terra-money/terra.proto": "^4.0.9",
"assert": "^2.0.0",
"axios": "^0.27.2",
"bech32": "^2.0.0",
Expand Down
3 changes: 3 additions & 0 deletions src/client/lcd/LCDClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ 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 @@ -135,6 +136,7 @@ export class LCDClient {
public ibcTransfer: IbcTransferAPI;
public pob: PobAPI;
public feeshare: FeeshareAPI;
public feemarket: FeemarketAPI;
public utils: LCDUtils;

/**
Expand Down Expand Up @@ -185,6 +187,7 @@ export class LCDClient {
this.tx = new TxAPI(this);
this.pob = new PobAPI(this);
this.feeshare = new FeeshareAPI(this);
this.feemarket = new FeemarketAPI(this);
this.utils = new LCDUtils(this);
}

Expand Down
83 changes: 83 additions & 0 deletions src/client/lcd/api/Feemarket.API.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import Decimal from 'decimal.js';
import {
FeemarketDenomParams,
FeemarketParams,
FeemarketState,
} from '../../../core/feemarket';
import { LCDClient } from '../LCDClient';
import { FeemarketAPI } from './FeemarketAPI';

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

describe('FeemarketAPI', () => {
it('asset the module params', async () => {
const res = await feemarket.params('pisco-1');

expect(res).toStrictEqual(
new FeemarketParams(
new Decimal(0),
new Decimal(1),
new Decimal(0),
new Decimal(0.125),
new Decimal(0.125),
new Decimal(15000000),
new Decimal(30000000),
new Decimal(1),
true,
'uluna'
)
);

expect(res.toData()).toEqual({
alpha: '0',
beta: '1',
theta: '0',
min_learning_rate: '0.125',
max_learning_rate: '0.125',
target_block_utilization: '15000000',
max_block_utilization: '30000000',
window: '1',
enabled: true,
default_fee_denom: 'uluna',
});
});

it('asset the module state', async () => {
const res = await feemarket.state('pisco-1');
expect(res).toStrictEqual(
new FeemarketState(new Decimal(0.125), [new Decimal(0)], new Decimal(0))
);
expect(res.toData()).toEqual({
learning_rate: '0.125',
window: ['0'],
index: '0',
});
});

it('get fee denom params', async () => {
const res = await feemarket.feeDenomParam('pisco-1', 'uluna');
expect(res).toStrictEqual([
new FeemarketDenomParams(
'uluna',
new Decimal('0.0015'),
new Decimal('0.0015')
),
]);
expect(res[0].toData()).toEqual({
fee_denom: 'uluna',
min_base_fee: '0.0015',
base_fee: '0.0015',
});
});
});
67 changes: 67 additions & 0 deletions src/client/lcd/api/FeemarketAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {
FeemarketDenomParams,
FeemarketParams,
FeemarketState,
} from '../../../core/feemarket';
import { APIParams, PaginationOptions } from '../APIRequester';
import { LCDClient } from '../LCDClient';
import { BaseAPI } from './BaseAPI';

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

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

return FeemarketParams.fromData(res.params);
}

/**
* Query feemarket state.
*
* @tags Query
* @name state
* @request GET:/feemarket/v1/state
*/
public async state(chainId: string, params: Partial<APIParams> = {}) {
const res = await this.getReqFromChainID(chainId).get<{
state: FeemarketState.Data;
}>(`/feemarket/v1/state`, params);

return FeemarketState.fromData(res.state);
}

/**
* Query the current feeDenomParam for fee_denom.
*
* @tags Query
* @name feeDenomParam
* @summary Query the current feeDenomParam for fee_denom.
* @request GET:/feemarket/v1/fee_denom_param/${feeDenom} or GET:/feemarket/v1/fee_denom_param/
*/
public async feeDenomParam(
chainId: string,
feeDenom: string,
params?: Partial<PaginationOptions & APIParams>
): Promise<Array<FeemarketDenomParams>> {
const res = await this.getReqFromChainID(chainId).get<{
fee_denom_params: Array<FeemarketDenomParams.Data>;
}>(`/feemarket/v1/fee_denom_param/${feeDenom}`, params);

return res.fee_denom_params.map(x => FeemarketDenomParams.fromData(x));
}
}
1 change: 1 addition & 0 deletions src/core/alliance/proposals/v1/MsgCreateAlliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export class MsgCreateAlliance extends JSONSerializable<
rewardChangeInterval,
rewardWeightRange,
} = this;

return MsgCreateAlliance_pb.fromPartial({
authority,
denom,
Expand Down
6 changes: 6 additions & 0 deletions src/core/feemarket/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './v1/models/FeemarketParams';
export * from './v1/proposals/MsgFeeDenomParam';
export * from './v1/proposals/MsgRemoveFeeDenomParam';
export * from './v1/proposals/MsgParams';
export * from './v1/models/FeemarketState';
export * from './v1/models/FeemarketDenomParams';
103 changes: 103 additions & 0 deletions src/core/feemarket/v1/models/FeemarketDenomParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { FeeDenomParam as FeeDenomParam_pb } from '@terra-money/terra.proto/feemarket/feemarket/v1/genesis';
import { Denom } from 'core/Denom';
import Decimal from 'decimal.js';
import { JSONSerializable } from '../../../../util/json';

export class FeemarketDenomParams extends JSONSerializable<
FeemarketDenomParams.Amino,
FeemarketDenomParams.Data,
FeemarketDenomParams.Proto
> {
constructor(
public feeDenom: Denom,
public minBaseFee: Decimal,
public baseFee: Decimal
) {
super();
}

public static fromAmino(
data: FeemarketDenomParams.Amino
): FeemarketDenomParams {
const {
value: { fee_denom, min_base_fee, base_fee },
} = data;

return new FeemarketDenomParams(
fee_denom,
new Decimal(min_base_fee),
new Decimal(base_fee)
);
}

public toAmino(): FeemarketDenomParams.Amino {
const { feeDenom, minBaseFee, baseFee } = this;

return {
value: {
fee_denom: feeDenom,
min_base_fee: minBaseFee.toString(),
base_fee: baseFee.toString(),
},
};
}

public static fromData(
data: FeemarketDenomParams.Data,
_?: boolean
): FeemarketDenomParams {
_;
const { fee_denom, min_base_fee, base_fee } = data;
return new FeemarketDenomParams(
fee_denom,
new Decimal(min_base_fee),
new Decimal(base_fee)
);
}

public toData(_?: boolean): FeemarketDenomParams.Data {
_;
const { feeDenom, minBaseFee, baseFee } = this;
return {
fee_denom: feeDenom,
min_base_fee: minBaseFee.toString(),
base_fee: baseFee.toString(),
};
}

public static fromProto(
proto: FeemarketDenomParams.Proto
): FeemarketDenomParams {
return new FeemarketDenomParams(
proto.feeDenom,
new Decimal(proto.minBaseFee),
new Decimal(proto.baseFee)
);
}

public toProto(): FeemarketDenomParams.Proto {
const { feeDenom, minBaseFee, baseFee } = this;
return {
feeDenom,
minBaseFee: minBaseFee.toString(),
baseFee: baseFee.toString(),
};
}
}

export namespace FeemarketDenomParams {
export interface Amino {
value: {
fee_denom: string;
min_base_fee: string;
base_fee: string;
};
}

export interface Data {
fee_denom: string;
min_base_fee: string;
base_fee: string;
}
export type Proto = FeeDenomParam_pb;
}
Loading
Loading