@pioneer-platform/osmosis-client 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -10,63 +10,4 @@ interface QuoteResult {
10
10
  slippage: string;
11
11
  }
12
12
  declare function quoteFromPool(amountAtomSwap: string, amountAtomPool: string, amountOsmoPool: string): QuoteResult;
13
- declare const build_swap_tx: (from: string, tokenIn: string, tokenOut: string, amountIn: string, tokenOutMinAmount: string) => Promise<{
14
- account_number: any;
15
- chain_id: string;
16
- fee: {
17
- amount: {
18
- amount: string;
19
- denom: string;
20
- }[];
21
- gas: string;
22
- };
23
- memo: string;
24
- msg: {
25
- type: string;
26
- value: {
27
- routes: {
28
- pool_id: string;
29
- token_out_denom: string;
30
- }[];
31
- sender: string;
32
- token_in: {
33
- amount: string;
34
- denom: string;
35
- };
36
- token_out_min_amount: string;
37
- };
38
- }[];
39
- sequence: string;
40
- } | undefined>;
41
- declare const build_ibc_tx: (from: string, to: string, amount: string) => Promise<{
42
- account_number: any;
43
- chain_id: string;
44
- fee: {
45
- amount: {
46
- amount: string;
47
- denom: string;
48
- }[];
49
- gas: string;
50
- };
51
- memo: string;
52
- msg: {
53
- type: string;
54
- value: {
55
- receiver: string;
56
- sender: string;
57
- source_channel: string;
58
- source_port: string;
59
- timeout_height: {
60
- revision_height: string;
61
- revision_number: string;
62
- };
63
- token: {
64
- amount: string;
65
- denom: string;
66
- };
67
- };
68
- }[];
69
- signatures: never[];
70
- sequence: any;
71
- } | undefined>;
72
13
  declare const get_quote: (quote: any) => Promise<any>;
package/lib/index.js CHANGED
@@ -86,145 +86,16 @@ function quoteFromPool(amountAtomSwap, amountAtomPool, amountOsmoPool) {
86
86
  slippage: Math.max(slippage, 0).toFixed(6)
87
87
  };
88
88
  }
89
- //
90
- var build_swap_tx = function (from, tokenIn, tokenOut, amountIn, tokenOutMinAmount) {
91
- return __awaiter(this, void 0, void 0, function () {
92
- var tag, accountInfo, tx, e_1;
93
- return __generator(this, function (_a) {
94
- switch (_a.label) {
95
- case 0:
96
- tag = TAG + " | build_swap_tx | ";
97
- _a.label = 1;
98
- case 1:
99
- _a.trys.push([1, 3, , 4]);
100
- return [4 /*yield*/, networkOsmo.getAccount(from)];
101
- case 2:
102
- accountInfo = _a.sent();
103
- log.info(tag, "accountInfo: ", accountInfo);
104
- if (!accountInfo.account.account_number)
105
- throw new Error("missing account_number");
106
- tx = {
107
- "account_number": accountInfo.account.account_number,
108
- "chain_id": 'osmosis-1',
109
- "fee": {
110
- "amount": [
111
- {
112
- "amount": "2291",
113
- "denom": "uosmo"
114
- }
115
- ],
116
- "gas": "100000"
117
- },
118
- "memo": "memo",
119
- "msg": [
120
- {
121
- "type": "osmosis/gamm/swap-exact-amount-in",
122
- "value": {
123
- "routes": [
124
- {
125
- "pool_id": "1",
126
- "token_out_denom": tokenOut
127
- }
128
- ],
129
- "sender": from,
130
- "token_in": {
131
- "amount": amountIn,
132
- "denom": tokenIn
133
- },
134
- "token_out_min_amount": "8204"
135
- }
136
- }
137
- ],
138
- "sequence": "90"
139
- };
140
- return [2 /*return*/, tx];
141
- case 3:
142
- e_1 = _a.sent();
143
- log.error(e_1);
144
- return [3 /*break*/, 4];
145
- case 4: return [2 /*return*/];
146
- }
147
- });
148
- });
149
- };
150
- var build_ibc_tx = function (from, to, amount) {
151
- return __awaiter(this, void 0, void 0, function () {
152
- var tag, accountInfo, currentHeight, expireBlockHeight, tx, e_2;
153
- return __generator(this, function (_a) {
154
- switch (_a.label) {
155
- case 0:
156
- tag = TAG + " | build_ibc_tx | ";
157
- _a.label = 1;
158
- case 1:
159
- _a.trys.push([1, 3, , 4]);
160
- log.info(tag, "from: ", from);
161
- log.info(tag, "to: ", to);
162
- log.info(tag, "amount: ", amount);
163
- return [4 /*yield*/, networkAtom.getAccount(to)];
164
- case 2:
165
- accountInfo = _a.sent();
166
- log.info(tag, "accountInfo: ", accountInfo);
167
- if (!accountInfo.result.value.account_number)
168
- throw new Error("missing account_number");
169
- if (!accountInfo.result.value.sequence)
170
- throw new Error("missing account_number");
171
- currentHeight = accountInfo.height;
172
- expireBlockHeight = parseInt(currentHeight) + 10000;
173
- tx = {
174
- "account_number": accountInfo.result.value.account_number,
175
- "chain_id": "cosmoshub-4",
176
- "fee": {
177
- "amount": [
178
- {
179
- "amount": "2800",
180
- "denom": "uatom"
181
- }
182
- ],
183
- "gas": "290000"
184
- },
185
- "memo": "",
186
- "msg": [
187
- {
188
- "type": "cosmos-sdk/MsgTransfer",
189
- "value": {
190
- "receiver": to,
191
- "sender": from,
192
- "source_channel": "channel-141",
193
- "source_port": "transfer",
194
- "timeout_height": {
195
- "revision_height": expireBlockHeight.toString(),
196
- "revision_number": "1"
197
- },
198
- "token": {
199
- "amount": amount,
200
- "denom": "uatom"
201
- }
202
- }
203
- }
204
- ],
205
- "signatures": [],
206
- "sequence": accountInfo.result.value.sequence
207
- };
208
- return [2 /*return*/, tx];
209
- case 3:
210
- e_2 = _a.sent();
211
- log.error(e_2);
212
- return [3 /*break*/, 4];
213
- case 4: return [2 /*return*/];
214
- }
215
- });
216
- });
217
- };
218
89
  var get_quote = function (quote) {
219
90
  return __awaiter(this, void 0, void 0, function () {
220
- var tag, output, pools, amountAtom, amountOsmo, rate, invocationId, result, tx1, tx2, tx2, tx1, e_3;
91
+ var tag, output, pools, amountAtom, amountOsmo, rate, invocationId, result, tx1, tx2, tx1, tx2, e_1;
221
92
  return __generator(this, function (_a) {
222
93
  switch (_a.label) {
223
94
  case 0:
224
95
  tag = TAG + " | get_quote | ";
225
96
  _a.label = 1;
226
97
  case 1:
227
- _a.trys.push([1, 10, , 11]);
98
+ _a.trys.push([1, 3, , 4]);
228
99
  output = {};
229
100
  if (!quote.sellAsset)
230
101
  throw new Error("missing sellAsset");
@@ -249,44 +120,79 @@ var get_quote = function (quote) {
249
120
  log.info(tag, "rate: ", rate);
250
121
  invocationId = uuid();
251
122
  output.invocationId = invocationId;
123
+ output.meta = {
124
+ quoteMode: "OSMOSIS-IBC"
125
+ };
252
126
  // get amountOut
253
127
  //2 steps
254
128
  output.steps = 2;
129
+ output.complete = true;
255
130
  result = void 0;
256
- if (!(quote.sellAsset === shortListSymbolToCaip["OSMO"])) return [3 /*break*/, 5];
257
- result = quoteFromPool(quote.sellAmount, amountAtom, amountOsmo);
258
- output.result = result;
259
- return [4 /*yield*/, build_swap_tx(quote.senderAddress, quote.sellAsset, quote.buyAsset, quote.sellAmount, result.amountOut)];
131
+ if (quote.sellAsset === shortListSymbolToCaip["OSMO"]) {
132
+ result = quoteFromPool(quote.sellAmount, amountAtom, amountOsmo);
133
+ output.result = result;
134
+ tx1 = {
135
+ type: "sendSwapTx",
136
+ chain: shortListSymbolToCaip["OSMO"],
137
+ txParams: {
138
+ senderAddress: quote.senderAddress,
139
+ sellAsset: quote.sellAsset,
140
+ buyAsset: quote.buyAsset,
141
+ sellAmount: quote.sellAmount,
142
+ buyAmountMin: result.amountOut
143
+ }
144
+ };
145
+ log.info(tag, "tx1: ", tx1);
146
+ tx2 = {
147
+ type: "ibcTransfer",
148
+ chain: shortListSymbolToCaip["ATOM"], // Assuming ATOM is the target chain for the IBC withdrawal
149
+ txParams: {
150
+ senderAddress: quote.senderAddress, // Address initiating the IBC withdrawal
151
+ recipientAddress: quote.recipientAddress, // Destination address for the ATOM tokens
152
+ amount: result.amountOut, // Amount of ATOM tokens to withdraw
153
+ // Other parameters required for the IBC withdrawal can be added here
154
+ }
155
+ };
156
+ log.info(tag, "tx2: ", tx2);
157
+ output.txs = [tx1, tx2];
158
+ }
159
+ else if (quote.sellAsset === shortListSymbolToCaip["ATOM"]) {
160
+ result = quoteFromPool(quote.sellAmount, amountAtom, amountOsmo);
161
+ output.result = result;
162
+ tx1 = {
163
+ type: "ibcTransfer",
164
+ chain: shortListSymbolToCaip["ATOM"],
165
+ txParams: {
166
+ senderAddress: quote.senderAddress, // Address initiating the IBC deposit
167
+ recipientAddress: quote.recipientAddress, // Osmosis address to receive ATOM
168
+ amount: quote.sellAmount, // Amount of ATOM tokens to deposit
169
+ // Other parameters for the IBC deposit can be added here
170
+ }
171
+ };
172
+ log.info(tag, "tx1: ", tx1);
173
+ tx2 = {
174
+ type: "sendSwapTx",
175
+ chain: shortListSymbolToCaip["OSMO"],
176
+ txParams: {
177
+ senderAddress: quote.senderAddress,
178
+ sellAsset: shortListSymbolToCaip["ATOM"],
179
+ buyAsset: quote.buyAsset,
180
+ sellAmount: result.amountOut, // Amount of ATOM obtained from the IBC deposit
181
+ buyAmountMin: quote.sellAmount // Minimum amount of OSMO to buy
182
+ }
183
+ };
184
+ log.info(tag, "tx2: ", tx2);
185
+ output.txs = [tx1, tx2];
186
+ }
187
+ else {
188
+ throw Error("Asset not supported! asset:" + quote.sellAsset);
189
+ }
190
+ return [2 /*return*/, output];
260
191
  case 3:
261
- tx1 = _a.sent();
262
- log.info(tag, "tx1: ", tx1);
263
- return [4 /*yield*/, build_ibc_tx(quote.senderAddress, quote.recipientAddress, result.amountOut)];
264
- case 4:
265
- tx2 = _a.sent();
266
- log.info(tag, "tx2: ", tx2);
267
- output.txs = [tx1, tx2];
268
- return [3 /*break*/, 9];
269
- case 5:
270
- if (!(quote.sellAsset === shortListSymbolToCaip["ATOM"])) return [3 /*break*/, 8];
271
- result = quoteFromPool(quote.sellAmount, amountAtom, amountOsmo);
272
- output.result = result;
273
- return [4 /*yield*/, build_ibc_tx(quote.recipientAddress, quote.senderAddress, result.amountOut)];
274
- case 6:
275
- tx2 = _a.sent();
276
- log.info(tag, "tx2: ", tx2);
277
- return [4 /*yield*/, build_swap_tx(quote.senderAddress, quote.sellAsset, quote.buyAsset, quote.sellAmount, result.amountOut)];
278
- case 7:
279
- tx1 = _a.sent();
280
- log.info(tag, "tx1: ", tx1);
281
- output.txs = [tx1, tx2];
282
- return [3 /*break*/, 9];
283
- case 8: throw Error("Asset not supported! asset:" + quote.sellAsset);
284
- case 9: return [2 /*return*/, output];
285
- case 10:
286
- e_3 = _a.sent();
287
- console.error(tag, "e: ", e_3);
288
- return [3 /*break*/, 11];
289
- case 11: return [2 /*return*/];
192
+ e_1 = _a.sent();
193
+ console.error(tag, "e: ", e_1);
194
+ return [3 /*break*/, 4];
195
+ case 4: return [2 /*return*/];
290
196
  }
291
197
  });
292
198
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/osmosis-client",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "dependencies": {