aftermath-ts-sdk 0.0.136 → 0.0.137
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/dist/packages/pools/api/poolsApiCasting.d.ts.map +1 -1
- package/dist/packages/pools/api/poolsApiCasting.js +7 -7
- package/dist/packages/router/utils/synchronous/routerGraph.d.ts.map +1 -1
- package/dist/packages/router/utils/synchronous/routerGraph.js +1 -13
- package/dist/packages/router/utils/synchronous/routerPools/aftermathRouterPool.d.ts.map +1 -1
- package/dist/packages/router/utils/synchronous/routerPools/aftermathRouterPool.js +16 -8
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poolsApiCasting.d.ts","sourceRoot":"","sources":["../../../../src/packages/pools/api/poolsApiCasting.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,QAAQ,EACR,iBAAiB,EAGjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEN,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,sBAAsB,EACtB,uBAAuB,EAEvB,qBAAqB,EACrB,wBAAwB,EACxB,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"poolsApiCasting.d.ts","sourceRoot":"","sources":["../../../../src/packages/pools/api/poolsApiCasting.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,QAAQ,EACR,iBAAiB,EAGjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEN,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,sBAAsB,EACtB,uBAAuB,EAEvB,qBAAqB,EACrB,wBAAwB,EACxB,MAAM,wBAAwB,CAAC;AAKhC,qBAAa,eAAe;IAK3B,OAAc,uBAAuB,cACzB,iBAAiB,KAC1B,UAAU,CA8CX;IAMF,OAAc,yBAAyB,2CAEpC,cAAc,CAiBf;IAEF,OAAc,2BAA2B,6CAEtC,gBAAgB,CAejB;IAEF,OAAc,4BAA4B,8CAEvC,iBAAiB,CAclB;IAEF,OAAc,sCAAsC,4CAEjD,QAAQ,CAGT;CACF"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PoolsApiCasting = void 0;
|
|
4
4
|
const sui_js_1 = require("@mysten/sui.js");
|
|
5
5
|
const coin_1 = require("../../coin");
|
|
6
|
+
const utils_1 = require("../../../general/utils");
|
|
6
7
|
class PoolsApiCasting {
|
|
7
8
|
}
|
|
8
9
|
exports.PoolsApiCasting = PoolsApiCasting;
|
|
@@ -12,8 +13,7 @@ exports.PoolsApiCasting = PoolsApiCasting;
|
|
|
12
13
|
PoolsApiCasting.poolObjectFromSuiObject = (suiObject) => {
|
|
13
14
|
const objectId = (0, sui_js_1.getObjectId)(suiObject);
|
|
14
15
|
const poolFieldsOnChain = (0, sui_js_1.getObjectFields)(suiObject);
|
|
15
|
-
const lpCoinType = new coin_1.Coin(poolFieldsOnChain.lp_supply.type)
|
|
16
|
-
.innerCoinType;
|
|
16
|
+
const lpCoinType = utils_1.Helpers.addLeadingZeroesToType(new coin_1.Coin(poolFieldsOnChain.lp_supply.type).innerCoinType);
|
|
17
17
|
const coins = poolFieldsOnChain.type_names.reduce((acc, cur, index) => {
|
|
18
18
|
return Object.assign(Object.assign({}, acc), { ["0x" + cur]: {
|
|
19
19
|
weight: BigInt(poolFieldsOnChain.weights[index]),
|
|
@@ -26,7 +26,7 @@ PoolsApiCasting.poolObjectFromSuiObject = (suiObject) => {
|
|
|
26
26
|
}, {});
|
|
27
27
|
return {
|
|
28
28
|
objectId,
|
|
29
|
-
lpCoinType
|
|
29
|
+
lpCoinType,
|
|
30
30
|
name: poolFieldsOnChain.name,
|
|
31
31
|
creator: poolFieldsOnChain.creator,
|
|
32
32
|
lpCoinSupply: BigInt(poolFieldsOnChain.lp_supply.fields.value),
|
|
@@ -43,9 +43,9 @@ PoolsApiCasting.poolTradeEventFromOnChain = (eventOnChain) => {
|
|
|
43
43
|
return {
|
|
44
44
|
poolId: fields.pool_id,
|
|
45
45
|
trader: fields.issuer,
|
|
46
|
-
typesIn: fields.types_in.map((type) => "0x" + type),
|
|
46
|
+
typesIn: fields.types_in.map((type) => utils_1.Helpers.addLeadingZeroesToType("0x" + type)),
|
|
47
47
|
amountsIn: fields.amounts_in,
|
|
48
|
-
typesOut: fields.types_out.map((type) => "0x" + type),
|
|
48
|
+
typesOut: fields.types_out.map((type) => utils_1.Helpers.addLeadingZeroesToType("0x" + type)),
|
|
49
49
|
amountsOut: fields.amounts_out,
|
|
50
50
|
timestamp: eventOnChain.timestampMs,
|
|
51
51
|
txnDigest: eventOnChain.id.txDigest,
|
|
@@ -58,7 +58,7 @@ PoolsApiCasting.poolDepositEventFromOnChain = (eventOnChain) => {
|
|
|
58
58
|
poolId: fields.pool_id,
|
|
59
59
|
depositor: fields.issuer,
|
|
60
60
|
// TODO: create a function for all this 0x nonsense
|
|
61
|
-
types: fields.types.map((type) => "0x" + type),
|
|
61
|
+
types: fields.types.map((type) => utils_1.Helpers.addLeadingZeroesToType("0x" + type)),
|
|
62
62
|
deposits: fields.deposits,
|
|
63
63
|
lpMinted: fields.lp_coins_minted,
|
|
64
64
|
timestamp: eventOnChain.timestampMs,
|
|
@@ -71,7 +71,7 @@ PoolsApiCasting.poolWithdrawEventFromOnChain = (eventOnChain) => {
|
|
|
71
71
|
return {
|
|
72
72
|
poolId: fields.pool_id,
|
|
73
73
|
withdrawer: fields.issuer,
|
|
74
|
-
types: fields.types.map((type) => "0x" + type),
|
|
74
|
+
types: fields.types.map((type) => utils_1.Helpers.addLeadingZeroesToType("0x" + type)),
|
|
75
75
|
withdrawn: fields.withdrawn,
|
|
76
76
|
lpBurned: fields.lp_coins_burned,
|
|
77
77
|
timestamp: eventOnChain.timestampMs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routerGraph.d.ts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QAC9C,UAAU,EAAE,QAAQ,CAAC;QACrB,aAAa,EAAE,OAAO,EAAE,CAAC;QACzB,WAAW,EAAE,QAAQ,CAAC;QACtB,QAAQ,CAAC,EAAE,UAAU,CAAC;QACtB,WAAW,CAAC,EAAE,iBAAiB,CAAC;KAChC,GAAG,wBAAwB,EAAE;IA+B9B,OAAO,CAAC,gBAAgB;IA0ExB,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAyDpC;IAMF,OAAO,CAAC,MAAM,CAAC,UAAU,CAiCvB;IAEF,OAAO,CAAC,MAAM,CAAC,oBAAoB,CAkDjC;IAEF,OAAO,CAAC,MAAM,CAAC,kBAAkB,CA8E/B;IAEF,OAAO,CAAC,uBAAuB,CA2C7B;IAEF,OAAO,CAAC,oCAAoC,CAoF1C;IAEF,OAAO,CAAC,uBAAuB,CA8D7B;IAEF,OAAO,CAAC,iCAAiC,CA6IvC;IAEF,OAAc,uBAAuB,WAC5B,UAAU,EAAE,UACZ,QAAQ,gBACF,OAAO,WACZ,QAAQ,KACf,kBAAkB,CAgCnB;IAEF,OAAO,CAAC,MAAM,CAAC,sCAAsC,CAuBnD;IAEF,OAAO,CAAC,MAAM,CAAC,wCAAwC,CAiBrD;IAEF,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAM3B;IAEJ,OAAO,CAAC,MAAM,CAAC,eAAe,CAI3B;IAEH,OAAO,CAAC,MAAM,CAAC,8CAA8C,CAqD3D;CACF"}
|
|
@@ -148,17 +148,6 @@ class RouterGraph {
|
|
|
148
148
|
referrer,
|
|
149
149
|
});
|
|
150
150
|
const coinOutAmountFromTrade = totalCoinOutAmount - path.coinOut.amount;
|
|
151
|
-
// let updatedPool: RouterPoolInterface;
|
|
152
|
-
// if (
|
|
153
|
-
// (totalCoinOutAmount ||
|
|
154
|
-
// coinOutAmountFromTrade ||
|
|
155
|
-
// currentCoinInAmount) === failedAmount
|
|
156
|
-
// ) {
|
|
157
|
-
// totalCoinOutAmount = failedAmount;
|
|
158
|
-
// coinOutAmountFromTrade = failedAmount;
|
|
159
|
-
// currentCoinInAmount = failedAmount;
|
|
160
|
-
// updatedPool = Helpers.deepCopy(pool);
|
|
161
|
-
// } else {
|
|
162
151
|
const updatedPool = pool.getUpdatedPoolAfterTrade(!isGivenAmountOut
|
|
163
152
|
? {
|
|
164
153
|
coinInType: path.coinIn.type,
|
|
@@ -172,7 +161,6 @@ class RouterGraph {
|
|
|
172
161
|
coinOutType: path.coinOut.type,
|
|
173
162
|
coinOutAmount: currentCoinInAmount,
|
|
174
163
|
});
|
|
175
|
-
// }
|
|
176
164
|
let newPath = Object.assign(Object.assign({}, path), { coinIn: Object.assign(Object.assign({}, path.coinIn), { amount: totalCoinInAmount }), coinOut: Object.assign(Object.assign({}, path.coinOut), { amount: totalCoinOutAmount }), spotPrice });
|
|
177
165
|
newRoute = Object.assign(Object.assign({}, newRoute), { paths: [...newRoute.paths, newPath] });
|
|
178
166
|
currentCoinInAmount = coinOutAmountFromTrade;
|
|
@@ -308,7 +296,7 @@ _a = RouterGraph;
|
|
|
308
296
|
/////////////////////////////////////////////////////////////////////
|
|
309
297
|
RouterGraph.defaultOptions = {
|
|
310
298
|
maxRouteLength: 3,
|
|
311
|
-
tradePartitionCount:
|
|
299
|
+
tradePartitionCount: 10,
|
|
312
300
|
minRoutesToCheck: 20,
|
|
313
301
|
maxGasCost: BigInt(500000000), // 0.5 SUI
|
|
314
302
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aftermathRouterPool.d.ts","sourceRoot":"","sources":["../../../../../../src/packages/router/utils/synchronous/routerPools/aftermathRouterPool.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,QAAQ,EACR,UAAU,EACV,mBAAmB,EACnB,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,OAAO,EACP,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,GAAG,EACH,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"aftermathRouterPool.d.ts","sourceRoot":"","sources":["../../../../../../src/packages/router/utils/synchronous/routerPools/aftermathRouterPool.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,QAAQ,EACR,UAAU,EACV,mBAAmB,EACnB,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,OAAO,EACP,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,GAAG,EACH,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAkB,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAGxE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAEhE,cAAM,mBAAoB,YAAW,mBAAmB;gBAK3C,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,GAAG,GAAG;IAYvD,QAAQ,CAAC,YAAY,eAAe;IACpC,QAAQ,CAAC,qBAAqB,SAAuB;IACrD,QAAQ,CAAC,aAAa,SAAS;IAE/B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,GAAG,CAAC;IACnC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,QAAQ,EAAE,CAAC;IAE/B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAO;IAMjC,YAAY,WAAY;QACvB,UAAU,EAAE,QAAQ,CAAC;QACrB,WAAW,EAAE,QAAQ,CAAC;KACtB,YAYC;IAEF,iBAAiB,WAAY;QAC5B,UAAU,EAAE,QAAQ,CAAC;QACrB,YAAY,EAAE,OAAO,CAAC;QACtB,WAAW,EAAE,QAAQ,CAAC;QACtB,QAAQ,CAAC,EAAE,UAAU,CAAC;KACtB,KAAG,OAAO,CAkDT;IAEF,4BAA4B,WAAY;QACvC,QAAQ,EAAE,YAAY,CAAC;QACvB,EAAE,EAAE,gBAAgB,CAAC;QACrB,MAAM,EAAE,QAAQ,GAAG,mBAAmB,CAAC;QACvC,YAAY,EAAE,OAAO,CAAC;QACtB,UAAU,EAAE,QAAQ,CAAC;QACrB,WAAW,EAAE,QAAQ,CAAC;QACtB,iBAAiB,EAAE,OAAO,CAAC;QAC3B,QAAQ,EAAE,QAAQ,CAAC;QACnB,QAAQ,CAAC,EAAE,UAAU,CAAC;KACtB;;;;;;;;;;;;;;MA2CC;IAEF,gBAAgB,WAAY;QAC3B,UAAU,EAAE,QAAQ,CAAC;QACrB,aAAa,EAAE,OAAO,CAAC;QACvB,WAAW,EAAE,QAAQ,CAAC;QACtB,QAAQ,CAAC,EAAE,UAAU,CAAC;KACtB,KAAG,OAAO,CAiCT;IAEF,yBAAyB,WAAY;QACpC,UAAU,EAAE,QAAQ,CAAC;QACrB,YAAY,EAAE,OAAO,CAAC;QACtB,WAAW,EAAE,QAAQ,CAAC;QACtB,aAAa,EAAE,OAAO,CAAC;KACvB,KAAG,mBAAmB,CAMrB;IAEF,wBAAwB,WAAY;QACnC,UAAU,EAAE,QAAQ,CAAC;QACrB,YAAY,EAAE,OAAO,CAAC;QACtB,WAAW,EAAE,QAAQ,CAAC;QACtB,aAAa,EAAE,OAAO,CAAC;KACvB,KAAG,mBAAmB,CA8BrB;CACF;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -20,10 +20,8 @@ class AftermathRouterPool {
|
|
|
20
20
|
// withdraw/deposit
|
|
21
21
|
if (inputs.coinInType === this.pool.lpCoinType ||
|
|
22
22
|
inputs.coinOutType === this.pool.lpCoinType) {
|
|
23
|
-
// TODO: do this calc
|
|
24
|
-
|
|
25
|
-
const smallAmountOut = this.getTradeAmountOut(Object.assign(Object.assign({}, inputs), { coinInAmount: smallAmountIn }));
|
|
26
|
-
return Number(smallAmountIn) / Number(smallAmountOut);
|
|
23
|
+
// TODO: do this calc for real
|
|
24
|
+
return 1;
|
|
27
25
|
}
|
|
28
26
|
// trade
|
|
29
27
|
return this.poolClass.getSpotPrice(inputs);
|
|
@@ -34,11 +32,21 @@ class AftermathRouterPool {
|
|
|
34
32
|
const lpRatio = this.poolClass.getWithdrawLpRatio({
|
|
35
33
|
lpCoinAmountOut: inputs.coinInAmount,
|
|
36
34
|
});
|
|
35
|
+
// TODO: move this estimation to helper function within sdk
|
|
36
|
+
const poolCoinOut = this.pool.coins[inputs.coinOutType];
|
|
37
|
+
const coinOutPoolBalance = poolCoinOut.balance;
|
|
38
|
+
const coinOutWeight = pools_1.Pools.coinWeightWithDecimals(poolCoinOut.weight);
|
|
39
|
+
const lpCoinSupply = Number(this.pool.lpCoinSupply);
|
|
40
|
+
const lpTotal = Number(inputs.coinInAmount);
|
|
41
|
+
const poolCoinAmount = lpTotal < 0
|
|
42
|
+
? 0
|
|
43
|
+
: Number(coinOutPoolBalance) *
|
|
44
|
+
(lpTotal / (lpCoinSupply * coinOutWeight));
|
|
45
|
+
const amountOutEstimate = BigInt(Math.floor(poolCoinAmount));
|
|
37
46
|
const amountsOuts = this.poolClass.getWithdrawAmountsOut({
|
|
38
47
|
lpRatio,
|
|
39
48
|
amountsOutDirection: {
|
|
40
|
-
|
|
41
|
-
[inputs.coinOutType]: inputs.coinInAmount,
|
|
49
|
+
[inputs.coinOutType]: amountOutEstimate,
|
|
42
50
|
},
|
|
43
51
|
referral: inputs.referrer !== undefined,
|
|
44
52
|
});
|
|
@@ -115,15 +123,15 @@ class AftermathRouterPool {
|
|
|
115
123
|
let newPoolObject = utils_1.Helpers.deepCopy(this.pool);
|
|
116
124
|
if (inputs.coinInType === this.pool.lpCoinType) {
|
|
117
125
|
// withdraw
|
|
118
|
-
newPoolObject.lpCoinSupply
|
|
126
|
+
newPoolObject.lpCoinSupply += inputs.coinInAmount;
|
|
119
127
|
newPoolObject.coins[inputs.coinOutType].balance -=
|
|
120
128
|
inputs.coinOutAmount;
|
|
121
129
|
}
|
|
122
130
|
else if (inputs.coinOutType === this.pool.lpCoinType) {
|
|
123
131
|
// deposit
|
|
124
|
-
newPoolObject.lpCoinSupply += inputs.coinInAmount;
|
|
125
132
|
newPoolObject.coins[inputs.coinInType].balance +=
|
|
126
133
|
inputs.coinInAmount;
|
|
134
|
+
newPoolObject.lpCoinSupply -= inputs.coinOutAmount;
|
|
127
135
|
}
|
|
128
136
|
else {
|
|
129
137
|
// trade
|