Skip to content

Commit 4b93588

Browse files
committed
extract slinky stuff into neutronjsplus
1 parent 8d5d087 commit 4b93588

File tree

4 files changed

+821
-878
lines changed

4 files changed

+821
-878
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"@cosmos-client/core": "^0.47.4",
4848
"@cosmos-client/cosmwasm": "^0.40.3",
4949
"@cosmos-client/ibc": "^1.2.1",
50-
"@neutron-org/neutronjsplus": "neutron-org/neutronjsplus#feat/sdk-50",
50+
"@neutron-org/neutronjsplus": "neutron-org/neutronjsplus#03fb9963d35104a180d9cf0ad7252e3914669395",
5151
"@types/lodash": "^4.14.182",
5252
"@types/long": "^5.0.0",
5353
"axios": "^0.27.2",

setup/.tool-versions

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs 16.20.0

src/testcases/parallel/slinky.test.ts

+42-117
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
WalletWrapper,
44
CosmosWrapper,
55
NEUTRON_DENOM,
6-
ADMIN_MODULE_ADDRESS,
76
} from '@neutron-org/neutronjsplus/dist/cosmos';
87
import { TestStateLocalCosmosTestNet } from '@neutron-org/neutronjsplus';
98
import { getWithAttempts } from '@neutron-org/neutronjsplus/dist/wait';
@@ -12,7 +11,6 @@ import {
1211
DaoMember,
1312
getDaoContracts,
1413
} from '@neutron-org/neutronjsplus/dist/dao';
15-
import axios from 'axios';
1614

1715
const config = require('../../config.json');
1816

@@ -58,10 +56,47 @@ describe('Neutron / Slinky', () => {
5856

5957
describe('submit proposal', () => {
6058
test('create proposal', async () => {
61-
proposalId = await daoMember1.submitSingleChoiceProposal(
59+
proposalId = await daoMember1.submitUpdateMarketMap(
6260
'Proposal for update marketmap',
6361
'Add new marketmap with currency pair',
64-
[updateMarketMapProposal()],
62+
[
63+
{
64+
ticker: {
65+
currency_pair: {
66+
Base: 'ETH',
67+
Quote: 'USDT',
68+
},
69+
decimals: 8,
70+
min_provider_count: 1,
71+
enabled: true,
72+
metadata_JSON: '{}',
73+
},
74+
providers: {
75+
providers: [
76+
{
77+
name: 'kucoin_ws',
78+
off_chain_ticker: 'eth-usdt',
79+
},
80+
],
81+
},
82+
paths: {
83+
paths: [
84+
{
85+
operations: [
86+
{
87+
provider: 'kucoin_ws',
88+
currency_pair: {
89+
Base: 'ETH',
90+
Quote: 'USDT',
91+
},
92+
invert: false,
93+
},
94+
],
95+
},
96+
],
97+
},
98+
},
99+
],
65100
'1000',
66101
);
67102
});
@@ -88,129 +123,19 @@ describe('Neutron / Slinky', () => {
88123
// wait to make sure we updated the price in oracle module
89124
await neutronChain.blockWaiter.waitBlocks(5);
90125
// check
91-
const res = await queryAllCurrencyPairs(neutronChain.sdk);
126+
const res = await neutronChain.queryOracleAllCurrencyPairs();
92127
expect(res.currency_pairs[0].Base).toBe('ETH');
93128
expect(res.currency_pairs[0].Quote).toBe('USDT');
94129
});
95130

96131
test('prices not empty', async () => {
97-
const res = await queryPrices(neutronChain.sdk, ['ETH/USDT']);
132+
const res = await neutronChain.queryOraclePrices(['ETH/USDT']);
98133
expect(+res.prices[0].price.price).toBeGreaterThan(0);
99134
});
100135

101136
test('eth price present', async () => {
102-
const res = await queryPrice(neutronChain.sdk, 'ETH', 'USDT');
137+
const res = await neutronChain.queryOraclePrice('ETH', 'USDT');
103138
expect(+res.price.price).toBeGreaterThan(0);
104139
});
105140
});
106141
});
107-
108-
const updateMarketMapMessage = JSON.stringify({
109-
'@type': '/slinky.marketmap.v1.MsgUpdateMarketMap',
110-
signer: ADMIN_MODULE_ADDRESS,
111-
create_markets: [
112-
{
113-
ticker: {
114-
currency_pair: {
115-
Base: 'ETH',
116-
Quote: 'USDT',
117-
},
118-
decimals: 8,
119-
min_provider_count: 1,
120-
enabled: true,
121-
metadata_JSON: '{}',
122-
},
123-
providers: {
124-
providers: [
125-
{
126-
name: 'kucoin_ws',
127-
off_chain_ticker: 'eth-usdt',
128-
},
129-
],
130-
},
131-
paths: {
132-
paths: [
133-
{
134-
operations: [
135-
{
136-
provider: 'kucoin_ws',
137-
currency_pair: {
138-
Base: 'ETH',
139-
Quote: 'USDT',
140-
},
141-
invert: false,
142-
},
143-
],
144-
},
145-
],
146-
},
147-
},
148-
],
149-
});
150-
151-
const updateMarketMapProposal = (): any => ({
152-
custom: {
153-
submit_admin_proposal: {
154-
admin_proposal: {
155-
proposal_execute_message: {
156-
message: updateMarketMapMessage,
157-
},
158-
},
159-
},
160-
},
161-
});
162-
163-
type GetPriceResponse = {
164-
price: {
165-
price: string;
166-
block_timestamp: string;
167-
block_height: string;
168-
};
169-
nonce: string;
170-
decimals: string;
171-
id: string;
172-
};
173-
174-
type GetPricesResponse = {
175-
prices: GetPriceResponse[];
176-
};
177-
178-
type CurrencyPair = {
179-
Quote: string;
180-
Base: string;
181-
};
182-
183-
type GetAllCurrencyPairsResponse = {
184-
currency_pairs: CurrencyPair[];
185-
};
186-
187-
const queryPrice = async (sdk: any, base: string, quote: string): Promise<GetPriceResponse> => {
188-
try {
189-
const req = await axios.get<any>(`${sdk.url}/slinky/oracle/v1/get_price`, {
190-
params: {
191-
'currency_pair.Base': base,
192-
'currency_pair.Quote': quote,
193-
},
194-
});
195-
return req.data;
196-
} catch (e) {
197-
if (e.response?.data?.message !== undefined) {
198-
throw new Error(e.response?.data?.message);
199-
}
200-
throw e;
201-
}
202-
};
203-
204-
const queryPrices = async (sdk: any, currencyPairIds: string[]): Promise<GetPricesResponse> => {
205-
const req = await axios.get(`${sdk.url}/slinky/oracle/v1/get_prices`, {
206-
params: { currency_pair_ids: currencyPairIds.join(',') },
207-
});
208-
209-
return req.data;
210-
};
211-
212-
const queryAllCurrencyPairs = async (sdk: any): Promise<GetAllCurrencyPairsResponse> => {
213-
const req = await axios.get(`${sdk.url}/slinky/oracle/v1/get_all_tickers`);
214-
215-
return req.data;
216-
};

0 commit comments

Comments
 (0)