-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from terra-money/feat/feemarket
feat: feemarket
- Loading branch information
Showing
14 changed files
with
879 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.