-
Notifications
You must be signed in to change notification settings - Fork 26
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 #35 from terra-money/feat/token/factory/api
feat: token factory query API
- Loading branch information
Showing
4 changed files
with
109 additions
and
9 deletions.
There are no files selected for viewing
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,47 @@ | ||
import { LCDClient } from '../LCDClient'; | ||
import { TokenFactory } from './TokenFactoryAPI'; | ||
|
||
// has a default list of endpoints that we can select with the first parameter | ||
// 'mainnet' | 'testnet' | 'local' | ||
// we can add more chains or overwrite the default settings with the second parameter | ||
const lcd = LCDClient.fromDefaultConfig('testnet'); | ||
const tokenFactory = new TokenFactory(lcd); | ||
|
||
describe('TokenFactory', () => { | ||
it('params', async () => { | ||
const param = await tokenFactory.params('pisco-1'); | ||
|
||
expect(param).toMatchObject({ | ||
params: { | ||
denom_creation_fee: [ | ||
{ | ||
denom: 'uluna', | ||
amount: '10000000', | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
it('denoms for creator', async () => { | ||
const res = await tokenFactory.denomsFromCreator( | ||
'terra1zdpgj8am5nqqvht927k3etljyl6a52kwqup0je' | ||
); | ||
|
||
expect(res.denoms[res.denoms.length - 1]).toEqual( | ||
'factory/terra1zdpgj8am5nqqvht927k3etljyl6a52kwqup0je/utest766e' | ||
); | ||
}); | ||
|
||
/* | ||
The following request does not work yet because the endpoint | ||
does recognize the url encoded denom. | ||
it('authority metadata', async () => { | ||
const res = await tokenFactory.authorityMetadata("pisco-1","factory/terra1zdpgj8am5nqqvht927k3etljyl6a52kwqup0je/utest766e"); | ||
expect(res) | ||
.toEqual("factory/terra1zdpgj8am5nqqvht927k3etljyl6a52kwqup0je/utest766e") | ||
}); | ||
*/ | ||
}); |
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,53 @@ | ||
import { APIParams } from '../APIRequester'; | ||
import { LCDClient } from '../LCDClient'; | ||
import { BaseAPI } from './BaseAPI'; | ||
import { QueryParamsResponse } from '@terra-money/terra.proto/cosmwasm/wasm/v1/query'; | ||
import { AccAddress } from 'core'; | ||
|
||
export interface DenomsFromCreatorResponse { | ||
denoms: string[]; | ||
} | ||
|
||
export interface AuthorityMetadataResponse { | ||
authority_metadata: { | ||
admin: AccAddress; | ||
}; | ||
} | ||
|
||
export class TokenFactory extends BaseAPI { | ||
constructor(public lcd: LCDClient) { | ||
super(lcd.apiRequesters, lcd.config); | ||
} | ||
|
||
public params( | ||
chainID: string, | ||
params: APIParams = {} | ||
): Promise<QueryParamsResponse> { | ||
return this.getReqFromChainID(chainID).get<QueryParamsResponse>( | ||
`/osmosis/tokenfactory/v1beta1/params`, | ||
params | ||
); | ||
} | ||
|
||
public denomsFromCreator( | ||
creator: AccAddress, | ||
params: APIParams = {} | ||
): Promise<DenomsFromCreatorResponse> { | ||
const req = this.getReqFromAddress(creator); | ||
|
||
return req.get<DenomsFromCreatorResponse>( | ||
`/osmosis/tokenfactory/v1beta1/denoms_from_creator/${creator}`, | ||
params | ||
); | ||
} | ||
|
||
/* | ||
The following request does not work yet because the endpoint | ||
does recognize the url encoded denom. | ||
public authorityMetadata(chainID: string, denom: string, params: APIParams = {}): Promise<AuthorityMetadataResponse> { | ||
return this.getReqFromChainID(chainID) | ||
.get<AuthorityMetadataResponse>(`/osmosis/tokenfactory/v1beta1/denoms/${denom}/authority_metadata`, params); | ||
} | ||
*/ | ||
} |
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