aftermath-ts-sdk 0.0.143 → 0.0.145
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/general/api/transactionsApiHelpers.d.ts.map +1 -1
- package/dist/general/api/transactionsApiHelpers.js +4 -6
- package/dist/general/historicalData/historicalData.d.ts +14 -0
- package/dist/general/historicalData/historicalData.d.ts.map +1 -0
- package/dist/general/historicalData/historicalData.js +41 -0
- package/dist/general/historicalData/historicalDataApi.d.ts +10 -0
- package/dist/general/historicalData/historicalDataApi.d.ts.map +1 -0
- package/dist/general/historicalData/historicalDataApi.js +20 -0
- package/dist/general/historicalData/historicalDataTypes.d.ts +10 -0
- package/dist/general/historicalData/historicalDataTypes.d.ts.map +1 -0
- package/dist/general/historicalData/historicalDataTypes.js +2 -0
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.d.ts +17 -0
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.d.ts.map +1 -0
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.js +115 -0
- package/dist/general/prices/coingecko/coinGeckoPricesApi.d.ts +19 -0
- package/dist/general/prices/coingecko/coinGeckoPricesApi.d.ts.map +1 -0
- package/dist/general/prices/coingecko/coinGeckoPricesApi.js +63 -0
- package/dist/general/prices/coingecko/coinGeckoTypes.d.ts +9 -0
- package/dist/general/prices/coingecko/coinGeckoTypes.d.ts.map +1 -0
- package/dist/general/prices/coingecko/coinGeckoTypes.js +2 -0
- package/dist/general/prices/prices.d.ts +7 -1
- package/dist/general/prices/prices.d.ts.map +1 -1
- package/dist/general/prices/prices.js +18 -5
- package/dist/general/prices/pyth/pythPricesApi.d.ts +1 -2
- package/dist/general/prices/pyth/pythPricesApi.d.ts.map +1 -1
- package/dist/general/prices/pyth/pythPricesApi.js +2 -2
- package/dist/general/prices/pyth/pythPricesApiHelpers.d.ts +1 -3
- package/dist/general/prices/pyth/pythPricesApiHelpers.d.ts.map +1 -1
- package/dist/general/prices/pyth/pythPricesApiHelpers.js +1 -3
- package/dist/general/providers/aftermath.d.ts +3 -1
- package/dist/general/providers/aftermath.d.ts.map +1 -1
- package/dist/general/providers/aftermath.js +2 -0
- package/dist/general/providers/aftermathApi.d.ts +6 -3
- package/dist/general/providers/aftermathApi.d.ts.map +1 -1
- package/dist/general/providers/aftermathApi.js +8 -3
- package/dist/general/types/suiTypes.d.ts +1 -1
- package/dist/general/types/suiTypes.d.ts.map +1 -1
- package/dist/general/utils/caller.d.ts.map +1 -1
- package/dist/general/utils/caller.js +4 -2
- package/dist/general/utils/helpers.js +1 -1
- package/dist/general/wallet/walletApi.d.ts.map +1 -1
- package/dist/general/wallet/walletApi.js +2 -2
- package/dist/packages/coin/api/coinApi.d.ts +1 -0
- package/dist/packages/coin/api/coinApi.d.ts.map +1 -1
- package/dist/packages/coin/api/coinApi.js +47 -10
- package/dist/packages/coin/api/coinApiHelpers.d.ts +1 -10
- package/dist/packages/coin/api/coinApiHelpers.d.ts.map +1 -1
- package/dist/packages/coin/api/coinApiHelpers.js +86 -56
- package/dist/packages/coin/coin.d.ts +10 -7
- package/dist/packages/coin/coin.d.ts.map +1 -1
- package/dist/packages/coin/coin.js +39 -14
- package/dist/packages/coin/coinTypes.d.ts +7 -1
- package/dist/packages/coin/coinTypes.d.ts.map +1 -1
- package/dist/packages/external/turbos/turbosApiHelpers.d.ts.map +1 -1
- package/dist/packages/external/turbos/turbosApiHelpers.js +0 -1
- package/dist/packages/faucet/api/faucetApi.d.ts +3 -1
- package/dist/packages/faucet/api/faucetApi.d.ts.map +1 -1
- package/dist/packages/faucet/api/faucetApi.js +5 -4
- package/dist/packages/pools/api/poolsApi.d.ts +20 -7
- package/dist/packages/pools/api/poolsApi.d.ts.map +1 -1
- package/dist/packages/pools/api/poolsApi.js +17 -15
- package/dist/packages/pools/api/poolsApiHelpers.d.ts +14 -4
- package/dist/packages/pools/api/poolsApiHelpers.d.ts.map +1 -1
- package/dist/packages/pools/api/poolsApiHelpers.js +14 -17
- package/dist/packages/pools/pool.d.ts +6 -3
- package/dist/packages/pools/pool.d.ts.map +1 -1
- package/dist/packages/pools/pool.js +24 -12
- package/dist/packages/pools/pools.d.ts +3 -2
- package/dist/packages/pools/pools.d.ts.map +1 -1
- package/dist/packages/pools/pools.js +3 -2
- package/dist/packages/pools/poolsTypes.d.ts +2 -2
- package/dist/packages/pools/poolsTypes.d.ts.map +1 -1
- package/dist/packages/router/api/routerApi.d.ts.map +1 -1
- package/dist/packages/router/router.d.ts +1 -1
- package/dist/packages/router/router.js +1 -1
- package/dist/packages/router/utils/synchronous/routerGraph.d.ts.map +1 -1
- package/dist/packages/router/utils/synchronous/routerGraph.js +0 -1
- package/dist/packages/router/utils/synchronous/routerPools/aftermathRouterPool.d.ts.map +1 -1
- package/dist/packages/router/utils/synchronous/routerPools/aftermathRouterPool.js +5 -4
- package/package.json +1 -1
|
@@ -12,15 +12,17 @@ import { TransactionsApiHelpers } from "../api/transactionsApiHelpers";
|
|
|
12
12
|
import { SuiApi } from "../../packages/sui/api/suiApi";
|
|
13
13
|
import { WalletApi } from "../wallet/walletApi";
|
|
14
14
|
import { RouterApi } from "../../packages/router/api/routerApi";
|
|
15
|
-
import { PlaceholderPricesApi } from "../prices/placeholder/placeholderPricesApi";
|
|
16
15
|
import { CapysApi } from "../../packages/capys/api/capysApi";
|
|
17
16
|
import { StakingApi } from "../../packages/staking/api/stakingApi";
|
|
18
17
|
import { NftAmmApi } from "../../packages/nftAmm/api/nftAmmApi";
|
|
19
18
|
import { ReferralVaultApi } from "../../packages/referralVault/api/referralVaultApi";
|
|
20
19
|
import { RouterProtocolName } from "../../types";
|
|
20
|
+
import { HistoricalDataApi } from "../historicalData/historicalDataApi";
|
|
21
|
+
import { CoinGeckoPricesApi } from "../prices/coingecko/coinGeckoPricesApi";
|
|
21
22
|
export declare class AftermathApi {
|
|
22
23
|
readonly provider: JsonRpcProvider;
|
|
23
24
|
readonly addresses: ConfigAddresses;
|
|
25
|
+
private readonly coinGeckoApiKey;
|
|
24
26
|
static helpers: {
|
|
25
27
|
dynamicFields: typeof DynamicFieldsApiHelpers;
|
|
26
28
|
events: typeof EventsApiHelpers;
|
|
@@ -32,7 +34,7 @@ export declare class AftermathApi {
|
|
|
32
34
|
coin: typeof CoinApi;
|
|
33
35
|
sui: typeof SuiApi;
|
|
34
36
|
};
|
|
35
|
-
constructor(provider: JsonRpcProvider, addresses: ConfigAddresses);
|
|
37
|
+
constructor(provider: JsonRpcProvider, addresses: ConfigAddresses, coinGeckoApiKey: string);
|
|
36
38
|
DynamicFields: () => DynamicFieldsApiHelpers;
|
|
37
39
|
Events: () => EventsApiHelpers;
|
|
38
40
|
Inspections: () => InspectionsApiHelpers;
|
|
@@ -40,7 +42,8 @@ export declare class AftermathApi {
|
|
|
40
42
|
Transactions: () => TransactionsApiHelpers;
|
|
41
43
|
Rpc: () => RpcApiHelpers;
|
|
42
44
|
Wallet: () => WalletApi;
|
|
43
|
-
Prices: () =>
|
|
45
|
+
Prices: () => CoinGeckoPricesApi;
|
|
46
|
+
HistoricalData: () => HistoricalDataApi;
|
|
44
47
|
Coin: () => CoinApi;
|
|
45
48
|
Sui: () => SuiApi;
|
|
46
49
|
Pools: () => PoolsApi;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aftermathApi.d.ts","sourceRoot":"","sources":["../../../src/general/providers/aftermathApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"aftermathApi.d.ts","sourceRoot":"","sources":["../../../src/general/providers/aftermathApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mDAAmD,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAE5E,qBAAa,YAAY;aAoCP,QAAQ,EAAE,eAAe;aACzB,SAAS,EAAE,eAAe;IAC1C,OAAO,CAAC,QAAQ,CAAC,eAAe;IAjCjC,OAAc,OAAO;;;;;;;;;;MAwBnB;gBAOe,QAAQ,EAAE,eAAe,EACzB,SAAS,EAAE,eAAe,EACzB,eAAe,EAAE,MAAM;IAelC,aAAa,gCAA2C;IACxD,MAAM,yBAAoC;IAC1C,WAAW,8BAAyC;IACpD,OAAO,0BAAqC;IAC5C,YAAY,+BAA0C;IACtD,GAAG,sBAAiC;IAMpC,MAAM,kBAA6B;IAEnC,MAAM,2BAAsD;IAC5D,cAAc,0BAAqD;IAMnE,IAAI,gBAA2B;IAC/B,GAAG,eAA0B;IAM7B,KAAK,iBAA4B;IACjC,MAAM,kBAA6B;IACnC,MAAM,eAAgB,kBAAkB,EAAE,eACjB;IACzB,KAAK,iBAA4B;IACjC,OAAO,mBAA8B;IACrC,MAAM,kBAA6B;IACnC,aAAa,yBAAoC;CACxD"}
|
|
@@ -13,18 +13,20 @@ const transactionsApiHelpers_1 = require("../api/transactionsApiHelpers");
|
|
|
13
13
|
const suiApi_1 = require("../../packages/sui/api/suiApi");
|
|
14
14
|
const walletApi_1 = require("../wallet/walletApi");
|
|
15
15
|
const routerApi_1 = require("../../packages/router/api/routerApi");
|
|
16
|
-
const placeholderPricesApi_1 = require("../prices/placeholder/placeholderPricesApi");
|
|
17
16
|
const capysApi_1 = require("../../packages/capys/api/capysApi");
|
|
18
17
|
const stakingApi_1 = require("../../packages/staking/api/stakingApi");
|
|
19
18
|
const nftAmmApi_1 = require("../../packages/nftAmm/api/nftAmmApi");
|
|
20
19
|
const referralVaultApi_1 = require("../../packages/referralVault/api/referralVaultApi");
|
|
20
|
+
const historicalDataApi_1 = require("../historicalData/historicalDataApi");
|
|
21
|
+
const coinGeckoPricesApi_1 = require("../prices/coingecko/coinGeckoPricesApi");
|
|
21
22
|
class AftermathApi {
|
|
22
23
|
/////////////////////////////////////////////////////////////////////
|
|
23
24
|
//// Constructor
|
|
24
25
|
/////////////////////////////////////////////////////////////////////
|
|
25
|
-
constructor(provider, addresses) {
|
|
26
|
+
constructor(provider, addresses, coinGeckoApiKey) {
|
|
26
27
|
this.provider = provider;
|
|
27
28
|
this.addresses = addresses;
|
|
29
|
+
this.coinGeckoApiKey = coinGeckoApiKey;
|
|
28
30
|
/////////////////////////////////////////////////////////////////////
|
|
29
31
|
//// Class Object Creation
|
|
30
32
|
/////////////////////////////////////////////////////////////////////
|
|
@@ -41,7 +43,9 @@ class AftermathApi {
|
|
|
41
43
|
//// Utils
|
|
42
44
|
/////////////////////////////////////////////////////////////////////
|
|
43
45
|
this.Wallet = () => new walletApi_1.WalletApi(this);
|
|
44
|
-
|
|
46
|
+
// public Prices = () => new PlaceholderPricesApi(this);
|
|
47
|
+
this.Prices = () => new coinGeckoPricesApi_1.CoinGeckoPricesApi(this.coinGeckoApiKey);
|
|
48
|
+
this.HistoricalData = () => new historicalDataApi_1.HistoricalDataApi(this.coinGeckoApiKey);
|
|
45
49
|
/////////////////////////////////////////////////////////////////////
|
|
46
50
|
//// General Packages
|
|
47
51
|
/////////////////////////////////////////////////////////////////////
|
|
@@ -59,6 +63,7 @@ class AftermathApi {
|
|
|
59
63
|
this.ReferralVault = () => new referralVaultApi_1.ReferralVaultApi(this);
|
|
60
64
|
this.provider = provider;
|
|
61
65
|
this.addresses = addresses;
|
|
66
|
+
this.coinGeckoApiKey = coinGeckoApiKey;
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
69
|
exports.AftermathApi = AftermathApi;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ObjectId, SuiAddress } from "@mysten/sui.js";
|
|
2
2
|
import { Balance } from "./generalTypes";
|
|
3
|
-
export type SuiNetwork = "DEVNET" | "TESTNET" | "LOCAL";
|
|
3
|
+
export type SuiNetwork = "DEVNET" | "TESTNET" | "LOCAL" | "MAINNET";
|
|
4
4
|
export interface ObjectTable<K, V> {
|
|
5
5
|
objectId: ObjectId;
|
|
6
6
|
size: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suiTypes.d.ts","sourceRoot":"","sources":["../../../src/general/types/suiTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"suiTypes.d.ts","sourceRoot":"","sources":["../../../src/general/types/suiTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAMzC,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAMpE,MAAM,WAAW,WAAW,CAAC,CAAC,EAAE,CAAC;IAChC,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACb;AACD,MAAM,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,UAAU;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,cAAc,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,gBAAgB,EAAE,UAAU,CAAC;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,SAAS,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,QAAQ,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,kBAAkB,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,uBAAuB;IACvC,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,CAAC,EAAE,UAAU,CAAC;CACxB;AAED,MAAM,WAAW,uBAAuB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC7B,aAAa,EAAE,uBAAuB,EAAE,CAAC;IACzC,KAAK,EAAE,cAAc,CAAC;CACtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caller.d.ts","sourceRoot":"","sources":["../../../src/general/utils/caller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EACN,aAAa,EACb,gBAAgB,EAGhB,GAAG,EACH,MAAM,aAAa,CAAC;AAGrB,qBAAa,MAAM;aAQD,OAAO,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAR3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAM;gBAOd,OAAO,CAAC,oBAAkB,EACzB,SAAS,GAAE,GAAQ;IAcrC,OAAO,CAAC,MAAM,CAAC,iBAAiB;
|
|
1
|
+
{"version":3,"file":"caller.d.ts","sourceRoot":"","sources":["../../../src/general/utils/caller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EACN,aAAa,EACb,gBAAgB,EAGhB,GAAG,EACH,MAAM,aAAa,CAAC;AAGrB,qBAAa,MAAM;aAQD,OAAO,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAR3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAM;gBAOd,OAAO,CAAC,oBAAkB,EACzB,SAAS,GAAE,GAAQ;IAcrC,OAAO,CAAC,MAAM,CAAC,iBAAiB;mBAQX,mBAAmB;IAQxC,OAAO,CAAC,aAAa,CAQnB;cAMc,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,EACpD,GAAG,EAAE,GAAG,EACR,IAAI,CAAC,EAAE,QAAQ,EACf,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,CAAC;cAsBF,mBAAmB,CAAC,QAAQ,GAAG,SAAS,EACvD,GAAG,EAAE,GAAG,EACR,IAAI,CAAC,EAAE,QAAQ,EACf,MAAM,CAAC,EAAE,WAAW;cAWL,cAAc,CAAC,SAAS,EAAE,QAAQ,GAAG,aAAa,EACjE,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,QAAQ,EACd,MAAM,CAAC,EAAE,WAAW;CAQrB"}
|
|
@@ -36,10 +36,12 @@ class Caller {
|
|
|
36
36
|
//// Private Methods
|
|
37
37
|
/////////////////////////////////////////////////////////////////////
|
|
38
38
|
static baseUrlForNetwork(network) {
|
|
39
|
+
if (network === "MAINNET")
|
|
40
|
+
return "https://aftermath.finance";
|
|
41
|
+
if (network === "TESTNET")
|
|
42
|
+
return "https://testnet.aftermath.finance";
|
|
39
43
|
if (network === "DEVNET")
|
|
40
44
|
return "https://devnet.aftermath.finance";
|
|
41
|
-
if (network === "TESTNET")
|
|
42
|
-
return "https://aftermath.finance";
|
|
43
45
|
if (network === "LOCAL")
|
|
44
46
|
return "http://localhost:3000";
|
|
45
47
|
return network;
|
|
@@ -36,7 +36,7 @@ Helpers.addLeadingZeroesToType = (type) => {
|
|
|
36
36
|
const expectedTypeLength = 64;
|
|
37
37
|
const splitType = type.replace("0x", "").split("::");
|
|
38
38
|
if (splitType.length !== 3)
|
|
39
|
-
throw new Error("invalid type");
|
|
39
|
+
throw new Error("invalid type: " + type);
|
|
40
40
|
const typeSuffix = "::" + splitType[1] + "::" + splitType[2];
|
|
41
41
|
const strippedType = splitType[0];
|
|
42
42
|
const typeLength = strippedType.length;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walletApi.d.ts","sourceRoot":"","sources":["../../../src/general/wallet/walletApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAG/D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEzE,qBAAa,SAAS;IAKT,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,YAAY;IAY5C,gBAAgB,YAAmB,UAAU,QAAQ,QAAQ,qBAMlE;IAIK,oBAAoB,YACjB,UAAU,KACjB,QAAQ,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"walletApi.d.ts","sourceRoot":"","sources":["../../../src/general/wallet/walletApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAG/D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEzE,qBAAa,SAAS;IAKT,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,YAAY;IAY5C,gBAAgB,YAAmB,UAAU,QAAQ,QAAQ,qBAMlE;IAIK,oBAAoB,YACjB,UAAU,KACjB,QAAQ,cAAc,CAAC,CAkBxB;IAQK,8BAA8B,YAC3B,UAAU,WACV,iBAAiB,UAClB,MAAM,wDAeb;CACF"}
|
|
@@ -37,8 +37,8 @@ class WalletApi {
|
|
|
37
37
|
const allBalances = yield this.Provider.provider.getAllBalances({
|
|
38
38
|
owner: address,
|
|
39
39
|
});
|
|
40
|
-
const coinsToBalance = allBalances.reduce((acc, balance
|
|
41
|
-
return Object.assign(Object.assign({}, acc), { [balance.coinType]: BigInt(balance.totalBalance) });
|
|
40
|
+
const coinsToBalance = allBalances.reduce((acc, balance) => {
|
|
41
|
+
return Object.assign(Object.assign({}, acc), { [helpers_1.Helpers.addLeadingZeroesToType(balance.coinType)]: BigInt(balance.totalBalance) });
|
|
42
42
|
}, {});
|
|
43
43
|
return coinsToBalance;
|
|
44
44
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coinApi.d.ts","sourceRoot":"","sources":["../../../../src/packages/coin/api/coinApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,qBAAa,OAAO;IAWP,OAAO,CAAC,QAAQ,CAAC,QAAQ;IANrC,SAAgB,OAAO,iBAAC;gBAMK,QAAQ,EAAE,YAAY;IAS5C,iBAAiB,SACjB,QAAQ,KACZ,QAAQ,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"coinApi.d.ts","sourceRoot":"","sources":["../../../../src/packages/coin/api/coinApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,qBAAa,OAAO;IAWP,OAAO,CAAC,QAAQ,CAAC,QAAQ;IANrC,SAAgB,OAAO,iBAAC;gBAMK,QAAQ,EAAE,YAAY;IAS5C,iBAAiB,SACjB,QAAQ,KACZ,QAAQ,YAAY,CAAC,CA4BtB;IAGF,OAAO,CAAC,oBAAoB,CAmD1B;CACF"}
|
|
@@ -34,15 +34,7 @@ class CoinApi {
|
|
|
34
34
|
}
|
|
35
35
|
catch (error) {
|
|
36
36
|
if (this.Provider.Pools().Helpers.isLpCoin(coin)) {
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
symbol: coinName.replaceAll(" ", "_").toUpperCase(),
|
|
40
|
-
id: null,
|
|
41
|
-
description: "Aftermath Finance LP",
|
|
42
|
-
name: coinName,
|
|
43
|
-
decimals: pools_1.Pools.constants.decimals.lpCoinDecimals,
|
|
44
|
-
iconUrl: null,
|
|
45
|
-
};
|
|
37
|
+
return this.createLpCoinMetadata(coin);
|
|
46
38
|
}
|
|
47
39
|
const coinClass = new coin_1.Coin(coin);
|
|
48
40
|
const symbol = coinClass.coinTypeSymbol;
|
|
@@ -51,12 +43,57 @@ class CoinApi {
|
|
|
51
43
|
symbol: symbol.toUpperCase(),
|
|
52
44
|
id: null,
|
|
53
45
|
description: `${symbol} (${packageName})`,
|
|
54
|
-
name: symbol
|
|
46
|
+
name: symbol
|
|
47
|
+
.split("_")
|
|
48
|
+
.map((word) => helpers_1.Helpers.capitalizeOnlyFirstLetter(word))
|
|
49
|
+
.join(" "),
|
|
55
50
|
decimals: 9,
|
|
56
51
|
iconUrl: null,
|
|
57
52
|
};
|
|
58
53
|
}
|
|
59
54
|
});
|
|
55
|
+
// NOTE: this is temporary until LP coin metadata issue is solved on Sui
|
|
56
|
+
this.createLpCoinMetadata = (coin) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
try {
|
|
58
|
+
const PoolsApi = this.Provider.Pools();
|
|
59
|
+
// TODO: find the best way to do all of this using cached server data
|
|
60
|
+
const poolObjectId = yield PoolsApi.fetchPoolObjectIdForLpCoinType(coin);
|
|
61
|
+
const pool = yield PoolsApi.fetchPool(poolObjectId);
|
|
62
|
+
const maxCoinSymbolLength = 5;
|
|
63
|
+
const notPrettyCoinSymbol = pool.name.length > maxCoinSymbolLength
|
|
64
|
+
? pool.name.toUpperCase().slice(0, maxCoinSymbolLength)
|
|
65
|
+
: pool.name.toUpperCase();
|
|
66
|
+
const coinSymbol = notPrettyCoinSymbol.slice(-1) === "_"
|
|
67
|
+
? notPrettyCoinSymbol.slice(0, -1)
|
|
68
|
+
: notPrettyCoinSymbol;
|
|
69
|
+
const coinName = pool.name
|
|
70
|
+
.split(" ")
|
|
71
|
+
.map((word) => helpers_1.Helpers.capitalizeOnlyFirstLetter(word))
|
|
72
|
+
.join(" ");
|
|
73
|
+
const coinDescription = yield PoolsApi.Helpers.createLpCoinMetadataDescription({
|
|
74
|
+
poolName: pool.name,
|
|
75
|
+
coinTypes: Object.keys(pool.coins),
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
symbol: `AF_LP_${coinSymbol}`,
|
|
79
|
+
id: null,
|
|
80
|
+
description: coinDescription,
|
|
81
|
+
name: `Af Lp ${coinName}`,
|
|
82
|
+
decimals: pools_1.Pools.constants.decimals.lpCoinDecimals,
|
|
83
|
+
iconUrl: null,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
return {
|
|
88
|
+
symbol: "AF_LP",
|
|
89
|
+
id: null,
|
|
90
|
+
description: "Aftermath Finance LP",
|
|
91
|
+
name: "Af Lp",
|
|
92
|
+
decimals: pools_1.Pools.constants.decimals.lpCoinDecimals,
|
|
93
|
+
iconUrl: null,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
});
|
|
60
97
|
this.Provider = Provider;
|
|
61
98
|
this.Helpers = new coinApiHelpers_1.CoinApiHelpers(Provider);
|
|
62
99
|
}
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
import { SuiAddress, TransactionArgument, TransactionBlock } from "@mysten/sui.js";
|
|
2
|
-
import { Balance,
|
|
2
|
+
import { Balance, CoinType } from "../../../types";
|
|
3
3
|
import { AftermathApi } from "../../../general/providers/aftermathApi";
|
|
4
4
|
export declare class CoinApiHelpers {
|
|
5
5
|
private readonly Provider;
|
|
6
6
|
constructor(Provider: AftermathApi);
|
|
7
|
-
fetchCoinDecimals: (coin: CoinType) => Promise<number>;
|
|
8
|
-
fetchCoinDecimalsNormalizeBalance: (coin: CoinType, amount: number) => Promise<bigint>;
|
|
9
|
-
fetchCoinDecimalsApplyToBalance: (coin: CoinType, balance: Balance) => Promise<number>;
|
|
10
|
-
fetchCoinsToDecimals: (coins: CoinType[]) => Promise<Record<string, number>>;
|
|
11
|
-
fetchNormalizeCoinAmounts: (coins: CoinType[], amounts: number[]) => Promise<bigint[]>;
|
|
12
|
-
fetchCoinsToDecimalsAndPrices(coins: CoinType[]): Promise<Record<CoinType, {
|
|
13
|
-
decimals: CoinDecimal;
|
|
14
|
-
price: number;
|
|
15
|
-
}>>;
|
|
16
7
|
static formatCoinTypesForMoveCall: (coins: CoinType[]) => number[][];
|
|
17
8
|
fetchCoinWithAmountTx: (inputs: {
|
|
18
9
|
tx: TransactionBlock;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coinApiHelpers.d.ts","sourceRoot":"","sources":["../../../../src/packages/coin/api/coinApiHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,UAAU,EACV,mBAAmB,EACnB,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"coinApiHelpers.d.ts","sourceRoot":"","sources":["../../../../src/packages/coin/api/coinApiHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,UAAU,EACV,mBAAmB,EACnB,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAGvE,qBAAa,cAAc;IAKd,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,YAAY;IA2GnD,OAAc,0BAA0B,UAAW,QAAQ,EAAE,gBACG;IAMzD,qBAAqB,WAAkB;QAC7C,EAAE,EAAE,gBAAgB,CAAC;QACrB,aAAa,EAAE,UAAU,CAAC;QAC1B,QAAQ,EAAE,QAAQ,CAAC;QACnB,UAAU,EAAE,OAAO,CAAC;KACpB,KAAG,QAAQ,mBAAmB,CAAC,CAW9B;IAEK,sBAAsB,WAAkB;QAC9C,EAAE,EAAE,gBAAgB,CAAC;QACrB,aAAa,EAAE,UAAU,CAAC;QAC1B,SAAS,EAAE,QAAQ,EAAE,CAAC;QACtB,WAAW,EAAE,OAAO,EAAE,CAAC;KACvB,KAAG,QAAQ,mBAAmB,EAAE,CAAC,CA4BhC;IAUF,OAAO,CAAC,iCAAiC,CAmCvC;IAMF,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAgD7B;CACF"}
|
|
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.CoinApiHelpers = void 0;
|
|
13
13
|
const helpers_1 = require("../../../general/utils/helpers");
|
|
14
14
|
const coin_1 = require("../coin");
|
|
15
|
-
const coinApi_1 = require("./coinApi");
|
|
16
15
|
const casting_1 = require("../../../general/utils/casting");
|
|
17
16
|
class CoinApiHelpers {
|
|
18
17
|
/////////////////////////////////////////////////////////////////////
|
|
@@ -21,46 +20,6 @@ class CoinApiHelpers {
|
|
|
21
20
|
constructor(Provider) {
|
|
22
21
|
this.Provider = Provider;
|
|
23
22
|
/////////////////////////////////////////////////////////////////////
|
|
24
|
-
//// Public Methods
|
|
25
|
-
/////////////////////////////////////////////////////////////////////
|
|
26
|
-
/////////////////////////////////////////////////////////////////////
|
|
27
|
-
//// Fetching
|
|
28
|
-
/////////////////////////////////////////////////////////////////////
|
|
29
|
-
this.fetchCoinDecimals = (coin) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
const coinMetadata = yield new coinApi_1.CoinApi(this.Provider).fetchCoinMetadata(coin);
|
|
31
|
-
const decimals = coinMetadata === null || coinMetadata === void 0 ? void 0 : coinMetadata.decimals;
|
|
32
|
-
if (decimals === undefined)
|
|
33
|
-
throw Error("unable to obtain decimals for coin: " + coin);
|
|
34
|
-
return decimals;
|
|
35
|
-
});
|
|
36
|
-
// TODO: use this everywhere in backend calls ?
|
|
37
|
-
// TODO: handle coins where there is no coin metadata on chain
|
|
38
|
-
this.fetchCoinDecimalsNormalizeBalance = (coin, amount) => __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
const decimals = yield this.fetchCoinDecimals(coin);
|
|
40
|
-
return coin_1.Coin.normalizeBalance(amount, decimals);
|
|
41
|
-
});
|
|
42
|
-
this.fetchCoinDecimalsApplyToBalance = (coin, balance) => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
const decimals = yield this.fetchCoinDecimals(coin);
|
|
44
|
-
return coin_1.Coin.balanceWithDecimals(balance, decimals);
|
|
45
|
-
});
|
|
46
|
-
this.fetchCoinsToDecimals = (coins) => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
let allDecimals = [];
|
|
48
|
-
for (const coin of coins) {
|
|
49
|
-
const decimals = yield this.fetchCoinDecimals(coin);
|
|
50
|
-
allDecimals.push(decimals);
|
|
51
|
-
}
|
|
52
|
-
const coinsToDecimals = allDecimals.reduce((acc, decimals, index) => {
|
|
53
|
-
return Object.assign(Object.assign({}, acc), { [coins[index]]: decimals });
|
|
54
|
-
}, {});
|
|
55
|
-
return coinsToDecimals;
|
|
56
|
-
});
|
|
57
|
-
this.fetchNormalizeCoinAmounts = (coins, amounts) => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
const normalizedAmounts = yield Promise.all(coins.map((coin, index) => __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
return yield this.fetchCoinDecimalsNormalizeBalance(coin, amounts[index]);
|
|
60
|
-
})));
|
|
61
|
-
return normalizedAmounts;
|
|
62
|
-
});
|
|
63
|
-
/////////////////////////////////////////////////////////////////////
|
|
64
23
|
//// Transaction Builders
|
|
65
24
|
/////////////////////////////////////////////////////////////////////
|
|
66
25
|
this.fetchCoinWithAmountTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -116,24 +75,95 @@ class CoinApiHelpers {
|
|
|
116
75
|
});
|
|
117
76
|
this.Provider = Provider;
|
|
118
77
|
}
|
|
119
|
-
fetchCoinsToDecimalsAndPrices(coins) {
|
|
120
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
const [coinsToPrices, coinsToDecimals] = yield Promise.all([
|
|
122
|
-
this.Provider.Prices().fetchCoinsToPrice(coins),
|
|
123
|
-
this.fetchCoinsToDecimals(coins),
|
|
124
|
-
]);
|
|
125
|
-
const coinsToDecimalsAndPrices = Object.keys(coinsToPrices).reduce((acc, coin) => {
|
|
126
|
-
return Object.assign(Object.assign({}, acc), { [coin]: {
|
|
127
|
-
decimals: coinsToDecimals[coin],
|
|
128
|
-
price: coinsToPrices[coin] < 0 ? 0 : coinsToPrices[coin],
|
|
129
|
-
} });
|
|
130
|
-
}, {});
|
|
131
|
-
return coinsToDecimalsAndPrices;
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
78
|
}
|
|
135
79
|
exports.CoinApiHelpers = CoinApiHelpers;
|
|
136
80
|
/////////////////////////////////////////////////////////////////////
|
|
81
|
+
//// Public Methods
|
|
82
|
+
/////////////////////////////////////////////////////////////////////
|
|
83
|
+
/////////////////////////////////////////////////////////////////////
|
|
84
|
+
//// Fetching
|
|
85
|
+
/////////////////////////////////////////////////////////////////////
|
|
86
|
+
// public fetchCoinDecimals = async (coin: CoinType) => {
|
|
87
|
+
// const coinMetadata = await new CoinApi(this.Provider).fetchCoinMetadata(
|
|
88
|
+
// coin
|
|
89
|
+
// );
|
|
90
|
+
// const decimals = coinMetadata?.decimals;
|
|
91
|
+
// if (decimals === undefined)
|
|
92
|
+
// throw Error("unable to obtain decimals for coin: " + coin);
|
|
93
|
+
// return decimals as CoinDecimal;
|
|
94
|
+
// };
|
|
95
|
+
// TODO: use this everywhere in backend calls ?
|
|
96
|
+
// TODO: handle coins where there is no coin metadata on chain
|
|
97
|
+
// public fetchCoinDecimalsNormalizeBalance = async (
|
|
98
|
+
// coin: CoinType,
|
|
99
|
+
// amount: number
|
|
100
|
+
// ) => {
|
|
101
|
+
// const decimals = await this.fetchCoinDecimals(coin);
|
|
102
|
+
// return Coin.normalizeBalance(amount, decimals);
|
|
103
|
+
// };
|
|
104
|
+
// public fetchCoinDecimalsApplyToBalance = async (
|
|
105
|
+
// coin: CoinType,
|
|
106
|
+
// balance: Balance
|
|
107
|
+
// ) => {
|
|
108
|
+
// const decimals = await this.fetchCoinDecimals(coin);
|
|
109
|
+
// return Coin.balanceWithDecimals(balance, decimals);
|
|
110
|
+
// };
|
|
111
|
+
// public fetchCoinsToDecimals = async (coins: CoinType[]) => {
|
|
112
|
+
// let allDecimals: number[] = [];
|
|
113
|
+
// for (const coin of coins) {
|
|
114
|
+
// const decimals = await this.fetchCoinDecimals(coin);
|
|
115
|
+
// allDecimals.push(decimals);
|
|
116
|
+
// }
|
|
117
|
+
// const coinsToDecimals: Record<CoinType, CoinDecimal> =
|
|
118
|
+
// allDecimals.reduce((acc, decimals, index) => {
|
|
119
|
+
// return { ...acc, [coins[index]]: decimals };
|
|
120
|
+
// }, {});
|
|
121
|
+
// return coinsToDecimals;
|
|
122
|
+
// };
|
|
123
|
+
// public fetchNormalizeCoinAmounts = async (
|
|
124
|
+
// coins: CoinType[],
|
|
125
|
+
// amounts: number[]
|
|
126
|
+
// ) => {
|
|
127
|
+
// const normalizedAmounts = await Promise.all(
|
|
128
|
+
// coins.map(
|
|
129
|
+
// async (coin, index) =>
|
|
130
|
+
// await this.fetchCoinDecimalsNormalizeBalance(
|
|
131
|
+
// coin,
|
|
132
|
+
// amounts[index]
|
|
133
|
+
// )
|
|
134
|
+
// )
|
|
135
|
+
// );
|
|
136
|
+
// return normalizedAmounts;
|
|
137
|
+
// };
|
|
138
|
+
// public async fetchCoinsToDecimalsAndPrices(coins: CoinType[]): Promise<
|
|
139
|
+
// Record<
|
|
140
|
+
// CoinType,
|
|
141
|
+
// {
|
|
142
|
+
// decimals: CoinDecimal;
|
|
143
|
+
// price: number;
|
|
144
|
+
// }
|
|
145
|
+
// >
|
|
146
|
+
// > {
|
|
147
|
+
// const [coinsToPrices, coinsToDecimals] = await Promise.all([
|
|
148
|
+
// this.Provider.Prices().fetchCoinsToPrice(coins),
|
|
149
|
+
// this.fetchCoinsToDecimals(coins),
|
|
150
|
+
// ]);
|
|
151
|
+
// const coinsToDecimalsAndPrices = Object.keys(coinsToPrices).reduce(
|
|
152
|
+
// (acc, coin) => {
|
|
153
|
+
// return {
|
|
154
|
+
// ...acc,
|
|
155
|
+
// [coin]: {
|
|
156
|
+
// decimals: coinsToDecimals[coin],
|
|
157
|
+
// price:
|
|
158
|
+
// coinsToPrices[coin] < 0 ? 0 : coinsToPrices[coin],
|
|
159
|
+
// },
|
|
160
|
+
// };
|
|
161
|
+
// },
|
|
162
|
+
// {}
|
|
163
|
+
// );
|
|
164
|
+
// return coinsToDecimalsAndPrices;
|
|
165
|
+
// }
|
|
166
|
+
/////////////////////////////////////////////////////////////////////
|
|
137
167
|
//// Helpers
|
|
138
168
|
/////////////////////////////////////////////////////////////////////
|
|
139
169
|
CoinApiHelpers.formatCoinTypesForMoveCall = (coins) => coins.map((coin) => casting_1.Casting.u8VectorFromString(coin.slice(2))); // slice to remove 0x
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Balance, CoinDecimal, CoinsToBalance, CoinSymbol, CoinSymbolToCoinTypes, CoinType, CoinWithAmount, CoinWithAmountOrUndefined, KeyType } from "../../types";
|
|
1
|
+
import { Balance, CoinDecimal, CoinPriceInfo, CoinsToBalance, CoinsToDecimals, CoinSymbol, CoinSymbolToCoinTypes, CoinType, CoinWithAmount, CoinWithAmountOrUndefined, KeyType } from "../../types";
|
|
2
2
|
import { Caller } from "../../general/utils/caller";
|
|
3
3
|
import { CoinMetadata } from "@mysten/sui.js";
|
|
4
4
|
export declare class Coin extends Caller {
|
|
5
|
-
readonly coinType
|
|
5
|
+
readonly coinType?: string | undefined;
|
|
6
6
|
readonly network?: string | undefined;
|
|
7
7
|
static readonly constants: {
|
|
8
8
|
suiCoinType: string;
|
|
@@ -11,12 +11,15 @@ export declare class Coin extends Caller {
|
|
|
11
11
|
readonly coinTypeSymbol: string;
|
|
12
12
|
readonly innerCoinType: string;
|
|
13
13
|
metadata: CoinMetadata | undefined;
|
|
14
|
-
|
|
15
|
-
constructor(coinType
|
|
16
|
-
|
|
14
|
+
priceInfo: CoinPriceInfo | undefined;
|
|
15
|
+
constructor(coinType?: string | undefined, network?: string | undefined);
|
|
16
|
+
getCoinsToDecimals(inputs: {
|
|
17
|
+
coins: CoinType[];
|
|
18
|
+
}): Promise<CoinsToDecimals>;
|
|
19
|
+
getCoinMetadata(coin?: CoinType): Promise<CoinMetadata>;
|
|
17
20
|
setCoinMetadata(metadata: CoinMetadata): void;
|
|
18
|
-
getPrice(): Promise<
|
|
19
|
-
|
|
21
|
+
getPrice(coin?: CoinType): Promise<CoinPriceInfo>;
|
|
22
|
+
setPriceInfo(priceInfo: CoinPriceInfo): void;
|
|
20
23
|
static getCoinTypePackageName: (coin: CoinType) => string;
|
|
21
24
|
static getCoinTypeSymbol: (coin: CoinType) => string;
|
|
22
25
|
static getInnerCoinType: (coin: CoinType) => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coin.d.ts","sourceRoot":"","sources":["../../../src/packages/coin/coin.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,OAAO,EACP,WAAW,EACX,cAAc,EACd,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,cAAc,EACd,yBAAyB,EACzB,OAAO,EAGP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,qBAAa,IAAK,SAAQ,MAAM;
|
|
1
|
+
{"version":3,"file":"coin.d.ts","sourceRoot":"","sources":["../../../src/packages/coin/coin.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,OAAO,EACP,WAAW,EACX,aAAa,EACb,cAAc,EACd,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,cAAc,EACd,yBAAyB,EACzB,OAAO,EAGP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,qBAAa,IAAK,SAAQ,MAAM;aA0Bd,QAAQ,CAAC;aACT,OAAO,CAAC;IAtBzB,gBAAuB,SAAS;;MAE9B;IAMF,SAAgB,mBAAmB,EAAE,MAAM,CAAC;IAC5C,SAAgB,cAAc,EAAE,MAAM,CAAC;IACvC,SAAgB,aAAa,EAAE,MAAM,CAAC;IAE/B,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IACnC,SAAS,EAAE,aAAa,GAAG,SAAS,CAAC;gBAQ3B,QAAQ,CAAC,oBAAU,EACnB,OAAO,CAAC,oBAAkB;IAwB9B,kBAAkB,CAAC,MAAM,EAAE;QACvC,KAAK,EAAE,QAAQ,EAAE,CAAC;KAClB,GAAG,OAAO,CAAC,eAAe,CAAC;IAgBf,eAAe,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC;IAW7D,eAAe,CAAC,QAAQ,EAAE,YAAY;IAIhC,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC;IAiBvD,YAAY,CAAC,SAAS,EAAE,aAAa;IAa5C,OAAc,sBAAsB,SAAU,QAAQ,KAAG,MAAM,CAM7D;IAGF,OAAc,iBAAiB,SAAU,QAAQ,KAAG,MAAM,CASxD;IAEF,OAAc,gBAAgB,SAAU,QAAQ,YACW;IAE3D,OAAc,mBAAmB,YAAa,OAAO,YAInD;IAEF,OAAc,SAAS,SAAU,QAAQ,aAEuB;IAMhE,OAAc,uBAAuB,gBACvB,OAAO,QAAQ,EAAE,MAAM,CAAC;;;MAWpC;IAEF,OAAc,wBAAwB,mBACrB,cAAc;;;MAW7B;IAEF,OAAc,oBAAoB,4BACR,yBAAyB,GAAG,SAAS,KAC5D,cAAc,GAAG,SAAS,CAKmB;IAEhD,OAAc,qBAAqB,aACxB,QAAQ,yBACK,qBAAqB,KAC1C,UAAU,GAAG,SAAS,CAevB;IAcF,OAAc,gBAAgB,YACpB,MAAM,YACL,WAAW,KACnB,OAAO,CAIP;IAEH,OAAc,mBAAmB,WACxB,MAAM,GAAG,MAAM,YACb,MAAM,YAIf;IAEF,OAAc,sBAAsB,WAC3B,MAAM,GAAG,MAAM,YACb,MAAM,SACT,MAAM,YAGZ;CACF"}
|
|
@@ -17,14 +17,21 @@ class Coin extends caller_1.Caller {
|
|
|
17
17
|
/////////////////////////////////////////////////////////////////////
|
|
18
18
|
//// Constructor
|
|
19
19
|
/////////////////////////////////////////////////////////////////////
|
|
20
|
+
// TODO: update this class to not be instantiated with a coin type at all
|
|
20
21
|
constructor(coinType, network) {
|
|
21
22
|
super(network, "coins");
|
|
22
23
|
this.coinType = coinType;
|
|
23
24
|
this.network = network;
|
|
24
25
|
this.coinType = coinType;
|
|
25
|
-
this.coinTypePackageName =
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
this.coinTypePackageName = this.coinType
|
|
27
|
+
? Coin.getCoinTypePackageName(this.coinType)
|
|
28
|
+
: "";
|
|
29
|
+
this.coinTypeSymbol = this.coinType
|
|
30
|
+
? Coin.getCoinTypeSymbol(this.coinType)
|
|
31
|
+
: "";
|
|
32
|
+
this.innerCoinType = this.coinType
|
|
33
|
+
? Coin.getInnerCoinType(this.coinType)
|
|
34
|
+
: "";
|
|
28
35
|
}
|
|
29
36
|
/////////////////////////////////////////////////////////////////////
|
|
30
37
|
//// Public Methods
|
|
@@ -32,11 +39,25 @@ class Coin extends caller_1.Caller {
|
|
|
32
39
|
/////////////////////////////////////////////////////////////////////
|
|
33
40
|
//// Inspections
|
|
34
41
|
/////////////////////////////////////////////////////////////////////
|
|
35
|
-
|
|
42
|
+
getCoinsToDecimals(inputs) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const { coins } = inputs;
|
|
45
|
+
const allDecimals = yield Promise.all(coins.map((coin) => __awaiter(this, void 0, void 0, function* () { return (yield this.getCoinMetadata(coin)).decimals; })));
|
|
46
|
+
const coinsToDecimals = allDecimals.reduce((acc, decimals, index) => {
|
|
47
|
+
return Object.assign(Object.assign({}, acc), { [coins[index]]: decimals });
|
|
48
|
+
}, {});
|
|
49
|
+
return coinsToDecimals;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
getCoinMetadata(coin) {
|
|
53
|
+
var _a;
|
|
36
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
55
|
if (this.metadata)
|
|
38
56
|
return this.metadata;
|
|
39
|
-
const
|
|
57
|
+
const coinType = (_a = this.coinType) !== null && _a !== void 0 ? _a : coin;
|
|
58
|
+
if (!coinType)
|
|
59
|
+
throw new Error("no valid coin type");
|
|
60
|
+
const metadata = yield this.fetchApi(coinType);
|
|
40
61
|
this.setCoinMetadata(metadata);
|
|
41
62
|
return metadata;
|
|
42
63
|
});
|
|
@@ -44,21 +65,25 @@ class Coin extends caller_1.Caller {
|
|
|
44
65
|
setCoinMetadata(metadata) {
|
|
45
66
|
this.metadata = metadata;
|
|
46
67
|
}
|
|
47
|
-
getPrice() {
|
|
68
|
+
getPrice(coin) {
|
|
69
|
+
var _a;
|
|
48
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
if (this.
|
|
50
|
-
return this.
|
|
51
|
-
const
|
|
52
|
-
|
|
71
|
+
if (this.priceInfo !== undefined)
|
|
72
|
+
return this.priceInfo;
|
|
73
|
+
const coinType = (_a = this.coinType) !== null && _a !== void 0 ? _a : coin;
|
|
74
|
+
if (!coinType)
|
|
75
|
+
throw new Error("no valid coin type");
|
|
76
|
+
const priceInfo = yield new prices_1.Prices(this.network).getCoinPriceInfo({
|
|
77
|
+
coin: coinType,
|
|
53
78
|
});
|
|
54
79
|
// NOTE: do we want this here ? (unexpected behavior)
|
|
55
80
|
// if (price <= 0) throw new Error("No price found.")
|
|
56
|
-
this.
|
|
57
|
-
return
|
|
81
|
+
this.setPriceInfo(priceInfo);
|
|
82
|
+
return priceInfo;
|
|
58
83
|
});
|
|
59
84
|
}
|
|
60
|
-
|
|
61
|
-
this.
|
|
85
|
+
setPriceInfo(priceInfo) {
|
|
86
|
+
this.priceInfo = priceInfo;
|
|
62
87
|
}
|
|
63
88
|
}
|
|
64
89
|
exports.Coin = Coin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Balance } from "../../general/types/generalTypes";
|
|
1
|
+
import { Balance, Percentage } from "../../general/types/generalTypes";
|
|
2
2
|
export type CoinDecimal = number;
|
|
3
3
|
export type CoinType = string;
|
|
4
4
|
export type CoinSymbol = string;
|
|
@@ -20,5 +20,11 @@ export interface AmountInCoinAndUsd {
|
|
|
20
20
|
}
|
|
21
21
|
export type CoinsToBalance = Record<CoinType, Balance>;
|
|
22
22
|
export type CoinsToPrice = Record<CoinType, number>;
|
|
23
|
+
export type CoinsToDecimals = Record<CoinType, CoinDecimal>;
|
|
24
|
+
export type CoinsToPriceInfo = Record<CoinType, CoinPriceInfo>;
|
|
23
25
|
export type CoinSymbolToCoinTypes = Record<CoinSymbol, CoinType[]>;
|
|
26
|
+
export interface CoinPriceInfo {
|
|
27
|
+
price: number;
|
|
28
|
+
priceChange24HoursPercentage: Percentage;
|
|
29
|
+
}
|
|
24
30
|
//# sourceMappingURL=coinTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coinTypes.d.ts","sourceRoot":"","sources":["../../../src/packages/coin/coinTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"coinTypes.d.ts","sourceRoot":"","sources":["../../../src/packages/coin/coinTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAMvE,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AACjC,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC9B,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAMhC,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAEnE,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CACf;AACD,MAAM,WAAW,yBAAyB;IACzC,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B;AAMD,MAAM,WAAW,kBAAkB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CAClB;AAMD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACvD,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AACpD,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AAC5D,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;AAC/D,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC;AAEnE,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B,EAAE,UAAU,CAAC;CACzC"}
|