@pioneer-platform/osmosis-client 0.1.0 → 0.2.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @pioneer-platform/osmosis-client
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Automated minor version bump for all packages
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @pioneer-platform/cosmos-network@8.5.0
13
+ - @pioneer-platform/osmosis-network@8.5.0
14
+ - @pioneer-platform/loggerdog@8.5.0
15
+ - @pioneer-platform/pioneer-coins@9.5.0
16
+ - @pioneer-platform/pioneer-caip@9.4.0
17
+
18
+ ## 0.1.1
19
+
20
+ ### Patch Changes
21
+
22
+ - Automated patch version bump for all packages
23
+ - Updated dependencies
24
+ - @pioneer-platform/cosmos-network@8.4.1
25
+ - @pioneer-platform/osmosis-network@8.4.1
26
+ - @pioneer-platform/loggerdog@8.4.1
27
+ - @pioneer-platform/pioneer-coins@9.4.1
28
+ - @pioneer-platform/pioneer-caip@9.3.1
29
+
3
30
  ## 0.1.0
4
31
 
5
32
  ### Minor Changes
package/package.json CHANGED
@@ -1,19 +1,26 @@
1
1
  {
2
2
  "name": "@pioneer-platform/osmosis-client",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "dependencies": {
7
- "@pioneer-platform/cosmos-network": "^8.4.0",
8
- "@pioneer-platform/loggerdog": "^8.4.0",
9
- "@pioneer-platform/osmosis-network": "^8.4.0",
10
- "@pioneer-platform/pioneer-caip": "^9.3.0",
11
- "@pioneer-platform/pioneer-coins": "^9.4.0",
7
+ "@pioneer-platform/cosmos-network": "^8.5.0",
8
+ "@pioneer-platform/loggerdog": "^8.5.0",
9
+ "@pioneer-platform/osmosis-network": "^8.5.0",
10
+ "@pioneer-platform/pioneer-caip": "^9.4.0",
11
+ "@pioneer-platform/pioneer-coins": "^9.5.0",
12
12
  "axios": "^1.6.0",
13
13
  "dotenv": "^8.2.0",
14
14
  "rango-sdk": "^0.1.45",
15
15
  "uuidv4": "^6.2.13"
16
16
  },
17
+ "scripts": {
18
+ "npm": "pnpm i",
19
+ "test": "pnpm run build && node __tests__/test-module.js",
20
+ "build": "tsc -p .",
21
+ "prepublish": "pnpm run build",
22
+ "refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
23
+ },
17
24
  "devDependencies": {
18
25
  "@types/jest": "^25.2.3",
19
26
  "@types/node": "^18.16.0",
@@ -24,12 +31,5 @@
24
31
  "ts-jest": "^29.0.5",
25
32
  "typescript": "^5.0.4"
26
33
  },
27
- "gitHead": "a76012f6693a12181c4744e53e977a9eaeef0ed3",
28
- "scripts": {
29
- "npm": "pnpm i",
30
- "test": "pnpm run build && node __tests__/test-module.js",
31
- "build": "tsc -p .",
32
- "prepublish": "pnpm run build",
33
- "refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
34
- }
34
+ "gitHead": "a76012f6693a12181c4744e53e977a9eaeef0ed3"
35
35
  }
package/tsconfig.json CHANGED
@@ -17,7 +17,8 @@
17
17
  "esModuleInterop": true,
18
18
  "resolveJsonModule": true,
19
19
  "skipLibCheck": true,
20
- "forceConsistentCasingInFileNames": true
20
+ "forceConsistentCasingInFileNames": true,
21
+ "types": ["node"]
21
22
  },
22
23
  "include": ["src"],
23
24
  "exclude": ["node_modules", "**/__tests__/*"]
package/lib/index.d.ts DELETED
@@ -1,15 +0,0 @@
1
- declare const TAG = " | osmosis | ";
2
- declare const log: any;
3
- declare let caipToNetworkId: any, shortListSymbolToCaip: any, ChainToNetworkId: any;
4
- declare let networkOsmo: any;
5
- declare let networkAtom: any;
6
- declare const uuid: any;
7
- declare let networkSupport: any[];
8
- declare let assetSupport: any[];
9
- interface QuoteResult {
10
- amountOutMin: string;
11
- amountOut: string;
12
- slippage: string;
13
- }
14
- declare function quoteFromPool(amountAtomSwap: string, amountAtomPool: string, amountOsmoPool: string, maxSlippage: number): QuoteResult;
15
- declare const get_quote: (quote: any) => Promise<any>;
package/lib/index.js DELETED
@@ -1,175 +0,0 @@
1
- /*
2
- Osmosis Swap Intergration
3
- -Highlander
4
-
5
- */
6
- const TAG = " | osmosis | ";
7
- const log = require('@pioneer-platform/loggerdog')();
8
- let { caipToNetworkId, shortListSymbolToCaip, ChainToNetworkId } = require("@pioneer-platform/pioneer-caip");
9
- let networkOsmo = require("@pioneer-platform/osmosis-network");
10
- let networkAtom = require("@pioneer-platform/cosmos-network");
11
- const { uuid } = require('uuidv4');
12
- let networkSupport = [
13
- ChainToNetworkId["OSMO"],
14
- ChainToNetworkId["GAIA"],
15
- ];
16
- let assetSupport = [
17
- shortListSymbolToCaip["OSMO"],
18
- shortListSymbolToCaip["GAIA"],
19
- ];
20
- module.exports = {
21
- init: function (settings) {
22
- return true;
23
- },
24
- networkSupport: function () {
25
- return networkSupport;
26
- },
27
- assetSupport: function () {
28
- return assetSupport;
29
- },
30
- getQuote: function (quote) {
31
- return get_quote(quote);
32
- },
33
- };
34
- function quoteFromPool(amountAtomSwap, amountAtomPool, amountOsmoPool, maxSlippage) {
35
- // Convert string inputs to numbers and scale the swap amount
36
- const swapAmount = parseFloat(amountAtomSwap) * 1e6;
37
- const atomPoolAmount = parseFloat(amountAtomPool);
38
- const osmoPoolAmount = parseFloat(amountOsmoPool);
39
- // Calculate the constant product
40
- const k = atomPoolAmount * osmoPoolAmount;
41
- // New amount of ATOM in the pool after the swap
42
- const newAtomPoolAmount = atomPoolAmount + swapAmount;
43
- // Calculate the amount of OSMO received
44
- const newOsmoPoolAmount = k / newAtomPoolAmount;
45
- const osmoReceived = osmoPoolAmount - newOsmoPoolAmount;
46
- // Scale back down the amount of OSMO received
47
- const scaledOsmoReceived = osmoReceived / 1e6;
48
- // Calculate the actual rate of the swap
49
- const actualRate = scaledOsmoReceived / (swapAmount / 1e6);
50
- // Calculate the ideal rate
51
- const idealRate = osmoPoolAmount / atomPoolAmount;
52
- // Calculate the slippage
53
- const slippage = ((idealRate - actualRate) / idealRate) * 100;
54
- // Calculate amountOutMin considering the maximum slippage
55
- const amountOutMin = scaledOsmoReceived * (1 - maxSlippage / 100);
56
- return {
57
- amountOutMin: amountOutMin.toFixed(6).toString(),
58
- amountOut: scaledOsmoReceived.toFixed(6),
59
- slippage: Math.max(slippage, 0).toFixed(6)
60
- };
61
- }
62
- const get_quote = async function (quote) {
63
- let tag = TAG + " | get_quote | ";
64
- try {
65
- let output = {};
66
- if (!quote.sellAsset)
67
- throw new Error("missing sellAsset");
68
- if (!quote.buyAsset)
69
- throw new Error("missing buyAsset");
70
- if (!quote.sellAmount)
71
- throw new Error("missing sellAmount");
72
- if (!quote.senderAddress)
73
- throw new Error("missing senderAddress");
74
- if (!quote.recipientAddress)
75
- throw new Error("missing recipientAddress");
76
- if (!quote.slippage)
77
- throw new Error("missing slippage");
78
- //get pools
79
- let pools = await networkOsmo.getPools();
80
- if (!pools.pools[0])
81
- throw Error("Unable to get pools from network!");
82
- log.info(tag, "resp: ", pools.pools[0].pool_assets);
83
- let amountAtom = pools.pools[0].pool_assets[0].token.amount; // ATOM amount
84
- let amountOsmo = pools.pools[0].pool_assets[1].token.amount; // OSMO amount
85
- let rate = amountOsmo / amountAtom;
86
- output.rate = rate;
87
- log.info(tag, "rate: ", rate);
88
- //issue invocationId
89
- let invocationId = uuid();
90
- output.invocationId = invocationId;
91
- output.source = 'osmosis';
92
- output.meta = {
93
- quoteMode: "OSMOSIS-IBC"
94
- };
95
- // get amountOut
96
- //2 steps
97
- output.steps = 2;
98
- output.complete = true;
99
- let result;
100
- if (quote.sellAsset === shortListSymbolToCaip["OSMO"]) {
101
- result = quoteFromPool(quote.sellAmount, amountAtom, amountOsmo, quote.slippage);
102
- if (!result || !result.amountOut)
103
- throw new Error("Unable to get result from quoteFromPool");
104
- output.amountOut = result.amountOut;
105
- output.result = result;
106
- //build first TX
107
- //swap osmo for Atom IBC
108
- let tx1 = {
109
- type: "sendSwapTx",
110
- chain: caipToNetworkId(shortListSymbolToCaip["OSMO"]),
111
- txParams: {
112
- senderAddress: quote.senderAddress,
113
- tokenIn: 'uosmo',
114
- tokenOut: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2',
115
- amountIn: quote.sellAmount,
116
- amountOutMin: result.amountOutMin,
117
- }
118
- };
119
- log.info(tag, "tx1: ", tx1);
120
- //get balance ibc?
121
- //IBC withdrawal from osmo:atom to atom
122
- let tx2 = {
123
- type: "ibcTransfer",
124
- chain: caipToNetworkId(shortListSymbolToCaip["ATOM"]), // Assuming ATOM is the target chain for the IBC withdrawal
125
- txParams: {
126
- senderAddress: quote.senderAddress, // Address initiating the IBC withdrawal
127
- recipientAddress: quote.recipientAddress, // Destination address for the ATOM tokens
128
- amount: result.amountOut, // Amount of ATOM tokens to withdraw
129
- token: 'uatom' // Other parameters required for the IBC withdrawal can be added here
130
- }
131
- };
132
- log.info(tag, "tx2: ", tx2);
133
- output.txs = [tx1, tx2];
134
- }
135
- else if (quote.sellAsset === shortListSymbolToCaip["ATOM"]) {
136
- result = quoteFromPool(quote.sellAmount, amountAtom, amountOsmo, quote.slippage);
137
- output.result = result;
138
- //TODO audit this
139
- //deposit atom to osmo:atom IBC
140
- // Deposit ATOM to osmo:atom IBC
141
- let tx1 = {
142
- type: "ibcTransfer",
143
- chain: shortListSymbolToCaip["ATOM"],
144
- txParams: {
145
- senderAddress: quote.senderAddress, // Address initiating the IBC deposit
146
- recipientAddress: quote.recipientAddress, // Osmosis address to receive ATOM
147
- amount: quote.sellAmount, // Amount of ATOM tokens to deposit
148
- // Other parameters for the IBC deposit can be added here
149
- }
150
- };
151
- log.info(tag, "tx1: ", tx1);
152
- // Swap ATOM for OSMO
153
- let tx2 = {
154
- type: "sendSwapTx",
155
- chain: shortListSymbolToCaip["OSMO"],
156
- txParams: {
157
- senderAddress: quote.senderAddress,
158
- sellAsset: shortListSymbolToCaip["ATOM"],
159
- buyAsset: quote.buyAsset,
160
- sellAmount: result.amountOut, // Amount of ATOM obtained from the IBC deposit
161
- buyAmountMin: quote.sellAmount // Minimum amount of OSMO to buy
162
- }
163
- };
164
- log.info(tag, "tx2: ", tx2);
165
- output.txs = [tx1, tx2];
166
- }
167
- else {
168
- throw Error("Asset not supported! asset:" + quote.sellAsset);
169
- }
170
- return output;
171
- }
172
- catch (e) {
173
- console.error(tag, "e: ", e);
174
- }
175
- };