@sentio/sdk 2.57.13-rc.8 → 2.58.0-rc.1
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/aptos/codegen/codegen.d.ts.map +1 -1
- package/lib/aptos/codegen/codegen.js +13 -6
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/core/codegen.d.ts +2 -0
- package/lib/core/codegen.d.ts.map +1 -0
- package/lib/core/codegen.js +17 -0
- package/lib/core/codegen.js.map +1 -0
- package/lib/eth/codegen/codegen.d.ts.map +1 -1
- package/lib/eth/codegen/codegen.js +2 -1
- package/lib/eth/codegen/codegen.js.map +1 -1
- package/lib/fuel/codegen/codegen.d.ts.map +1 -1
- package/lib/fuel/codegen/codegen.js +6 -5
- package/lib/fuel/codegen/codegen.js.map +1 -1
- package/lib/solana/codegen/codegen.d.ts.map +1 -1
- package/lib/solana/codegen/codegen.js +7 -2
- package/lib/solana/codegen/codegen.js.map +1 -1
- package/lib/stark/codegen/codegen.d.ts.map +1 -1
- package/lib/stark/codegen/codegen.js +2 -1
- package/lib/stark/codegen/codegen.js.map +1 -1
- package/lib/store/codegen.js +52 -19
- package/lib/store/codegen.js.map +1 -1
- package/lib/store/store.d.ts +1 -1
- package/lib/store/store.d.ts.map +1 -1
- package/lib/store/store.js.map +1 -1
- package/lib/store/types.d.ts +2 -0
- package/lib/store/types.d.ts.map +1 -1
- package/lib/store/types.js +9 -1
- package/lib/store/types.js.map +1 -1
- package/lib/sui/codegen/codegen.d.ts.map +1 -1
- package/lib/sui/codegen/codegen.js +10 -3
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/utils/price.d.ts +4 -3
- package/lib/utils/price.d.ts.map +1 -1
- package/lib/utils/price.js +25 -20
- package/lib/utils/price.js.map +1 -1
- package/lib/utils/price.test.js.map +1 -1
- package/package.json +4 -4
- package/src/aptos/codegen/codegen.ts +16 -14
- package/src/core/codegen.ts +27 -0
- package/src/eth/codegen/codegen.ts +5 -1
- package/src/fuel/codegen/codegen.ts +6 -5
- package/src/solana/codegen/codegen.ts +9 -4
- package/src/stark/codegen/codegen.ts +2 -1
- package/src/store/codegen.ts +55 -19
- package/src/store/store.ts +3 -1
- package/src/store/types.ts +10 -1
- package/src/sui/codegen/codegen.ts +13 -3
- package/src/utils/price.ts +26 -20
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../../src/sui/codegen/codegen.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../../src/sui/codegen/codegen.ts"],"names":[],"mappings":"AAWA,wBAAsB,OAAO,CAC3B,OAAO,EAAE,MAAM,EACf,MAAM,SAA8B,EACpC,UAAU,UAAQ,EAClB,OAAO,UAAQ,iBAQhB"}
|
@@ -5,6 +5,7 @@ import { SuiCodegen as BaseSuiCodegen } from '@typemove/sui/codegen';
|
|
5
5
|
import path, { join } from 'path';
|
6
6
|
import { SharedNetworkCodegen } from '../../move/shared-network-codegen.js';
|
7
7
|
import { getRpcEndpoint, SuiNetwork } from '../network.js';
|
8
|
+
import { recursiveCodegen } from '../../core/codegen.js';
|
8
9
|
export async function codegen(abisDir, outDir = join('src', 'types', 'sui'), genExample = false, builtin = false) {
|
9
10
|
if (!fs.existsSync(abisDir)) {
|
10
11
|
return;
|
@@ -78,9 +79,15 @@ const MAINNET_CODEGEN = new SuiNetworkCodegen(SuiNetwork.MAIN_NET);
|
|
78
79
|
const TESTNET_CODEGEN = new SuiNetworkCodegen(SuiNetwork.TEST_NET);
|
79
80
|
class SuiCodegen {
|
80
81
|
async generate(srcDir, outputDir, builtin = false) {
|
81
|
-
|
82
|
-
const
|
83
|
-
|
82
|
+
let numFiles = 0;
|
83
|
+
const generators = [
|
84
|
+
['', MAINNET_CODEGEN],
|
85
|
+
['testnet', TESTNET_CODEGEN]
|
86
|
+
];
|
87
|
+
for (const [network, gen] of generators) {
|
88
|
+
numFiles += await recursiveCodegen(path.join(srcDir, network), path.join(outputDir, network), (src, dst) => gen.generate(src, dst, builtin));
|
89
|
+
}
|
90
|
+
return numFiles;
|
84
91
|
}
|
85
92
|
}
|
86
93
|
//# sourceMappingURL=codegen.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/sui/codegen/codegen.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAA0C,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACpF,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAA;AAC3E,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;
|
1
|
+
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/sui/codegen/codegen.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAA0C,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACpF,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAA;AAC3E,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAExD,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,OAAe,EACf,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,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,iBAAiB,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;AAClE,MAAM,eAAe,GAAG,IAAI,iBAAiB,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;AAElE,MAAM,UAAU;IACd,KAAK,CAAC,QAAQ,CAAC,MAAc,EAAE,SAAiB,EAAE,OAAO,GAAG,KAAK;QAC/D,IAAI,QAAQ,GAAG,CAAC,CAAA;QAChB,MAAM,UAAU,GAAkC;YAChD,CAAC,EAAE,EAAE,eAAe,CAAC;YACrB,CAAC,SAAS,EAAE,eAAe,CAAC;SAC7B,CAAA;QAED,KAAK,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,UAAU,EAAE,CAAC;YACxC,QAAQ,IAAI,MAAM,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CACzG,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAChC,CAAA;QACH,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF"}
|
package/lib/utils/price.d.ts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
import { CoinID } from '@sentio/protos';
|
2
2
|
import { ChainId } from '@sentio/chain';
|
3
|
-
import {
|
4
|
-
export declare function getPriceClient(basePath?: string):
|
3
|
+
import { PriceService } from '@sentio/api';
|
4
|
+
export declare function getPriceClient(basePath?: string): typeof PriceService;
|
5
|
+
type PriceApi = typeof PriceService;
|
5
6
|
interface PriceOptions {
|
6
7
|
toleranceInDays?: number;
|
7
8
|
}
|
@@ -24,6 +25,6 @@ export declare function getPriceBySymbol(symbol: string, date: Date, options?: P
|
|
24
25
|
* get coins that has price, return results are list of coin id with both symbol and address field set
|
25
26
|
* @param chainId
|
26
27
|
*/
|
27
|
-
export declare function getCoinsThatHasPrice(chainId: ChainId): Promise<import("@sentio/api").
|
28
|
+
export declare function getCoinsThatHasPrice(chainId: ChainId): Promise<import("@sentio/api").PriceServiceCoinId[]>;
|
28
29
|
export {};
|
29
30
|
//# sourceMappingURL=price.d.ts.map
|
package/lib/utils/price.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"price.d.ts","sourceRoot":"","sources":["../../src/utils/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,OAAO,
|
1
|
+
{"version":3,"file":"price.d.ts","sourceRoot":"","sources":["../../src/utils/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,OAAO,EAAU,YAAY,EAAE,MAAM,aAAa,CAAA;AAalD,wBAAgB,cAAc,CAAC,QAAQ,SAAkC,uBAYxE;AAOD,KAAK,QAAQ,GAAG,OAAO,YAAY,CAAA;AAGnC,UAAU,YAAY;IACpB,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAQD,wBAAsB,8BAA8B,CAClD,WAAW,EAAE,QAAQ,EACrB,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA8D7B;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAW7B;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAE7B;AAMD;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,OAAO,uDAkB1D"}
|
package/lib/utils/price.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Endpoints, processMetrics } from '@sentio/runtime';
|
2
2
|
import { LRUCache } from 'lru-cache';
|
3
|
-
import {
|
3
|
+
import { client, PriceService } from '@sentio/api';
|
4
4
|
import path from 'path';
|
5
5
|
import fs from 'fs';
|
6
6
|
import os from 'os';
|
@@ -13,18 +13,17 @@ function getApiKey() {
|
|
13
13
|
catch (e) { }
|
14
14
|
}
|
15
15
|
export function getPriceClient(basePath = Endpoints.INSTANCE.priceFeedAPI) {
|
16
|
-
if (!basePath.startsWith('http')) {
|
16
|
+
if (basePath && !basePath.startsWith('http')) {
|
17
17
|
basePath = 'http://' + basePath;
|
18
18
|
}
|
19
19
|
if (basePath.endsWith('/')) {
|
20
20
|
basePath = basePath.slice(0, -1);
|
21
21
|
}
|
22
|
-
|
23
|
-
basePath,
|
24
|
-
|
22
|
+
client.setConfig({
|
23
|
+
baseUrl: basePath || 'https://app.sentio.xyz',
|
24
|
+
auth: getApiKey()
|
25
25
|
});
|
26
|
-
|
27
|
-
return api;
|
26
|
+
return PriceService;
|
28
27
|
}
|
29
28
|
const priceMap = new LRUCache({
|
30
29
|
max: 100000,
|
@@ -53,21 +52,25 @@ export async function getPriceByTypeOrSymbolInternal(priceClient, date, coinId,
|
|
53
52
|
}
|
54
53
|
processMetrics.process_pricecall_count.add(1);
|
55
54
|
const response = priceClient.getPrice({
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
query: {
|
56
|
+
timestamp: date.toISOString(),
|
57
|
+
'coinId.symbol': coinId.symbol,
|
58
|
+
'coinId.address.address': coinId.address?.address,
|
59
|
+
'coinId.address.chain': coinId.address?.chain
|
60
|
+
}
|
60
61
|
});
|
61
62
|
price = response
|
62
63
|
.then((res) => {
|
63
|
-
|
64
|
-
|
64
|
+
const { data } = res;
|
65
|
+
if (data?.timestamp) {
|
66
|
+
const responseDate = new Date(data.timestamp);
|
67
|
+
const responseDateString = dateString(responseDate);
|
65
68
|
if (responseDateString === todayDateString) {
|
66
69
|
priceMap.delete(key);
|
67
70
|
}
|
68
71
|
else {
|
69
72
|
// https://www.javatpoint.com/javascript-date-difference
|
70
|
-
const diff = Math.abs(
|
73
|
+
const diff = Math.abs(responseDate.getTime() - date.getTime());
|
71
74
|
const daysDiff = diff / (1000 * 60 * 60 * 24);
|
72
75
|
const tolerance = options?.toleranceInDays || 2;
|
73
76
|
if (daysDiff > tolerance) {
|
@@ -79,7 +82,7 @@ export async function getPriceByTypeOrSymbolInternal(priceClient, date, coinId,
|
|
79
82
|
else {
|
80
83
|
priceMap.delete(key);
|
81
84
|
}
|
82
|
-
return
|
85
|
+
return data?.price;
|
83
86
|
})
|
84
87
|
.catch((e) => {
|
85
88
|
setTimeout(() => {
|
@@ -130,14 +133,16 @@ export async function getCoinsThatHasPrice(chainId) {
|
|
130
133
|
if (!priceClient) {
|
131
134
|
priceClient = getPriceClient();
|
132
135
|
}
|
133
|
-
const
|
134
|
-
|
135
|
-
|
136
|
+
const { data } = await priceClient.priceListCoins({
|
137
|
+
query: {
|
138
|
+
chain: chainId,
|
139
|
+
limit: 1000
|
140
|
+
}
|
136
141
|
});
|
137
|
-
if (!
|
142
|
+
if (!data?.coinAddressesInChain) {
|
138
143
|
return [];
|
139
144
|
}
|
140
|
-
return Object.entries(
|
145
|
+
return Object.entries(data.coinAddressesInChain).map(([symbol, coin]) => {
|
141
146
|
coin.symbol = symbol;
|
142
147
|
return coin;
|
143
148
|
});
|
package/lib/utils/price.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/utils/price.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;A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AM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAAgB;IACzD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,WAAW,GAAG,cAAc,EAAE,CAAA;IAChC,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,WAAW,CAAC,cAAc,CAAC;QAChD,KAAK,EAAE;YACL,KAAK,EAAE,OAAO;YACd,KAAK,EAAE,IAAI;SACZ;KACF,CAAC,CAAA;IAEF,IAAI,CAAC,IAAI,EAAE,oBAAoB,EAAE,CAAC;QAChC,OAAO,EAAE,CAAA;IACX,CAAC;IACD,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;QACtE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,OAAO,IAAI,CAAA;IACb,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"price.test.js","sourceRoot":"","sources":["../../src/utils/price.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,
|
1
|
+
{"version":3,"file":"price.test.js","sourceRoot":"","sources":["../../src/utils/price.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAe,MAAM,WAAW,CAAA;AAC7D,OAAO,EAAE,8BAA8B,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAG3E,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,MAAM,MAAM,GAAG,cAAc,EAAE,CAAA;IAE/B,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QAC5B,IAAI,UAAU,GAAG,CAAC,CAAA;QAClB,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,OAAqB,EAAE,EAAE;YACxD,OAAO,OAAO,CAAC,OAAO,CAAC;gBACrB,IAAI,EAAE;oBACJ,SAAS,EAAE,IAAI,IAAI,EAAE;oBACrB,KAAK,EAAE,UAAU,EAAE;iBACpB;aACF,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9B,MAAM,CAAC,GAAG,8BAA8B,CAAC,MAAM,EAAE,IAAI,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;YAC/E,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;QAChC,CAAC;QACD,mFAAmF;QACnF,wBAAwB;IAC1B,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,uBAAuB,EAAE,KAAK,EAAE,CAAc,EAAE,EAAE;QACrD,MAAM,KAAK,GAAG,MAAM,8BAA8B,CAAC,MAAM,EAAE,IAAI,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;QACzF,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,IAAI,KAAK,GAAG,CAAC,CAAC,CAAA;IACjC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/sdk",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.58.0-rc.1",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"type": "module",
|
6
6
|
"exports": {
|
@@ -57,7 +57,7 @@
|
|
57
57
|
"@mysten/sui": "~1.20.0",
|
58
58
|
"@prettier/sync": "^0.5.2",
|
59
59
|
"@sentio/abi-wan-kanabi": "2.2.2-1",
|
60
|
-
"@sentio/api": "1.0.2
|
60
|
+
"@sentio/api": "1.0.2",
|
61
61
|
"@sentio/bigdecimal": "9.1.1-patch.3",
|
62
62
|
"@sentio/chain": "~3.0.5",
|
63
63
|
"@sentio/ethers-v6": "^1.0.29",
|
@@ -88,8 +88,8 @@
|
|
88
88
|
"typechain": "^8.3.2",
|
89
89
|
"utility-types": "^3.11.0",
|
90
90
|
"yaml": "^2.3.4",
|
91
|
-
"@sentio/protos": "2.
|
92
|
-
"@sentio/runtime": "^2.
|
91
|
+
"@sentio/protos": "2.58.0-rc.1",
|
92
|
+
"@sentio/runtime": "^2.58.0-rc.1"
|
93
93
|
},
|
94
94
|
"peerDependencies": {
|
95
95
|
"tsup": "npm:@sentio/tsup@^8.3.5-rc.1"
|
@@ -6,6 +6,7 @@ import { InternalMoveModule, InternalMoveStruct } from '@typemove/move'
|
|
6
6
|
import { AptosNetwork, getRpcEndpoint } from '../network.js'
|
7
7
|
import { Event, MoveModuleBytecode, MoveResource } from '@aptos-labs/ts-sdk'
|
8
8
|
import { SharedNetworkCodegen } from '../../move/shared-network-codegen.js'
|
9
|
+
import { recursiveCodegen } from '../../core/codegen.js'
|
9
10
|
|
10
11
|
export async function codegen(
|
11
12
|
abisDir: string,
|
@@ -64,7 +65,7 @@ class AptosNetworkCodegen extends BaseAptosCodegen {
|
|
64
65
|
import { TypeDescriptor, ANY_TYPE } from "@typemove/move"
|
65
66
|
import {
|
66
67
|
MoveCoder, TypedEventInstance } from "@typemove/${this.PREFIX.toLowerCase()}"
|
67
|
-
|
68
|
+
|
68
69
|
import { defaultMoveCoder, defaultMoveCoderForClient } from "${this.defaultCoderPackage()}"
|
69
70
|
import { Aptos, Account as AptosAccount, MoveAddressType, PendingTransactionResponse, InputGenerateTransactionOptions, MoveStructId, InputViewFunctionData } from '@aptos-labs/ts-sdk'`
|
70
71
|
)
|
@@ -81,18 +82,19 @@ const MOVEMENT_TESTNET_CODEGEN = new AptosNetworkCodegen(AptosNetwork.MOVEMENT_T
|
|
81
82
|
|
82
83
|
class AptosCodegen {
|
83
84
|
async generate(srcDir: string, outputDir: string, builtin = false): Promise<number> {
|
84
|
-
|
85
|
-
const
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
path.join(outputDir,
|
94
|
-
|
95
|
-
|
96
|
-
|
85
|
+
let numFiles = 0
|
86
|
+
const generators: [string, AptosNetworkCodegen][] = [
|
87
|
+
['', MAINNET_CODEGEN],
|
88
|
+
['testnet', TESTNET_CODEGEN],
|
89
|
+
['movement-mainnet', MOVEMENT_MAINNET_CODEGEN],
|
90
|
+
['movement-testnet', MOVEMENT_TESTNET_CODEGEN]
|
91
|
+
]
|
92
|
+
|
93
|
+
for (const [network, gen] of generators) {
|
94
|
+
numFiles += await recursiveCodegen(path.join(srcDir, network), path.join(outputDir, network), (src, dst) =>
|
95
|
+
gen.generate(src, dst, builtin)
|
96
|
+
)
|
97
|
+
}
|
98
|
+
return numFiles
|
97
99
|
}
|
98
100
|
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import fs from 'fs'
|
2
|
+
import path from 'path'
|
3
|
+
|
4
|
+
export async function recursiveCodegen(
|
5
|
+
abisDir: string,
|
6
|
+
outDir: string,
|
7
|
+
codegenInternal: (abisDir: string, outDir: string) => Promise<number>
|
8
|
+
) {
|
9
|
+
if (!fs.existsSync(abisDir)) {
|
10
|
+
return 0
|
11
|
+
}
|
12
|
+
|
13
|
+
let numFiles = await codegenInternal(abisDir, outDir)
|
14
|
+
|
15
|
+
const items = await fs.readdirSync(abisDir, { recursive: true, withFileTypes: true })
|
16
|
+
for (const item of items) {
|
17
|
+
if (item.isDirectory()) {
|
18
|
+
const relativePath = path.relative(abisDir, item.parentPath)
|
19
|
+
numFiles += await codegenInternal(
|
20
|
+
path.join(abisDir, relativePath, item.name),
|
21
|
+
path.join(outDir, relativePath, item.name)
|
22
|
+
)
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
return numFiles
|
27
|
+
}
|
@@ -8,13 +8,17 @@ import path from 'path'
|
|
8
8
|
import { mkdirpSync } from 'mkdirp'
|
9
9
|
import { YamlContractConfig } from '../../core/yaml-contract-config.js'
|
10
10
|
import chalk from 'chalk'
|
11
|
+
import { recursiveCodegen } from '../../core/codegen.js'
|
11
12
|
|
12
13
|
export async function codegen(abisDir: string, outDir: string, contractsToGenExample: YamlContractConfig[] = []) {
|
13
14
|
if (!fs.existsSync(abisDir)) {
|
14
15
|
return
|
15
16
|
}
|
16
17
|
|
17
|
-
const numFiles = await
|
18
|
+
const numFiles = await recursiveCodegen(abisDir, outDir, (src, dst) =>
|
19
|
+
codegenInternal(src, dst, contractsToGenExample)
|
20
|
+
)
|
21
|
+
|
18
22
|
console.log(chalk.green(`Generated ${numFiles} files for ETH`))
|
19
23
|
}
|
20
24
|
|
@@ -5,13 +5,14 @@ import { mkdirpSync } from 'mkdirp'
|
|
5
5
|
import path from 'path'
|
6
6
|
import { upperFirst } from './utils.js'
|
7
7
|
import { versions as builtinVersions } from '@fuel-ts/versions'
|
8
|
+
import { recursiveCodegen } from '../../core/codegen.js'
|
8
9
|
|
9
10
|
export async function codegen(abisDir: string, outDir: string) {
|
10
11
|
if (!fs.existsSync(abisDir)) {
|
11
12
|
return
|
12
13
|
}
|
13
14
|
|
14
|
-
const numFiles = await
|
15
|
+
const numFiles = await recursiveCodegen(abisDir, outDir, codegenInternal)
|
15
16
|
console.log(chalk.green(`Generated ${numFiles} files for Fuel`))
|
16
17
|
}
|
17
18
|
|
@@ -114,7 +115,7 @@ async function codegenInternal(abisDir: string, outDir: string): Promise<number>
|
|
114
115
|
|
115
116
|
/* tslint:disable */
|
116
117
|
/* eslint-disable */
|
117
|
-
|
118
|
+
|
118
119
|
import { FuelAbstractProcessor, FuelContractContext, FuelProcessorConfig, TypedCall, FuelFetchConfig, FuelCall, FuelLog, addFuelProcessor, getFuelProcessor, FuelBaseProcessorTemplate } from '@sentio/sdk/fuel'
|
119
120
|
import {${abi.commonTypesInUse.join(',')}} from './common.js'
|
120
121
|
import {${importedTypes.join(',')}, ${abi.capitalizedName}} from './${abi.capitalizedName}.js'
|
@@ -167,7 +168,7 @@ ${
|
|
167
168
|
''
|
168
169
|
/* disable codegen for now
|
169
170
|
abi.functions.map((f) => genOnCallFunction(name, f)).join('\n') */
|
170
|
-
}
|
171
|
+
}
|
171
172
|
|
172
173
|
${Object.entries(logByTypes)
|
173
174
|
.map((e) => genOnLogFunction(name, e))
|
@@ -209,7 +210,7 @@ function genCallType(f: IFunction) {
|
|
209
210
|
${Object.entries(argMap)
|
210
211
|
.map(([k, v]) => `${k}: ${v}`)
|
211
212
|
.join(', ')}
|
212
|
-
}
|
213
|
+
}
|
213
214
|
constructor(call: FuelCall) {
|
214
215
|
super(call)
|
215
216
|
}
|
@@ -261,7 +262,7 @@ function genOnLogFunction(contractName: string, [type, ids]: [string, string[]])
|
|
261
262
|
const logIdFilterValues = ids.map((_, idx) => `Log${name}Id${idx}`)
|
262
263
|
|
263
264
|
return `
|
264
|
-
onLog${name}(handler: (log: FuelLog<${type}>, ctx: FuelContractContext<${contractName}>) => void | Promise<void>,
|
265
|
+
onLog${name}(handler: (log: FuelLog<${type}>, ctx: FuelContractContext<${contractName}>) => void | Promise<void>,
|
265
266
|
logIdFilter?: LogIdFilter<${logIdFilterValues.map((d) => `typeof ${d}`).join(' | ')}> ) {
|
266
267
|
return super.onLog<${type}>(logIdFilter ?? [${logIdFilterValues.join(', ')}], (log, ctx) => handler(log, ctx))
|
267
268
|
}`
|
@@ -10,15 +10,21 @@ import {
|
|
10
10
|
IdlDefinedFields,
|
11
11
|
IdlTypeDef
|
12
12
|
} from '@coral-xyz/anchor/dist/esm/idl.js'
|
13
|
+
import { recursiveCodegen } from '../../core/codegen.js'
|
13
14
|
|
14
15
|
export function codegen(abisDir: string, targetPath = path.join('src', 'types', 'solana'), genExample = false) {
|
15
16
|
if (!fs.existsSync(abisDir)) {
|
16
17
|
return
|
17
18
|
}
|
18
19
|
|
19
|
-
const
|
20
|
-
|
20
|
+
const numFiles = recursiveCodegen(abisDir, targetPath, codegenInternal)
|
21
|
+
|
22
|
+
console.log(chalk.green(`Generated ${numFiles} for Solana`))
|
23
|
+
}
|
21
24
|
|
25
|
+
async function codegenInternal(abisDir: string, targetPath: string) {
|
26
|
+
let numFiles = 0
|
27
|
+
const abisFiles = fs.readdirSync(abisDir)
|
22
28
|
for (const file of abisFiles) {
|
23
29
|
if (path.extname(file) === '.json') {
|
24
30
|
if (!fs.existsSync(targetPath)) {
|
@@ -33,8 +39,7 @@ export function codegen(abisDir: string, targetPath = path.join('src', 'types',
|
|
33
39
|
numFiles += 2
|
34
40
|
}
|
35
41
|
}
|
36
|
-
|
37
|
-
console.log(chalk.green(`Generated ${numFiles} for Solana`))
|
42
|
+
return numFiles
|
38
43
|
}
|
39
44
|
|
40
45
|
function codeGenSolanaIdlProcessor(idlObj: Idl): string {
|
@@ -5,13 +5,14 @@ import { mkdirpSync } from 'mkdirp'
|
|
5
5
|
import { events } from 'starknet'
|
6
6
|
import { StarknetChainId } from '@sentio/chain'
|
7
7
|
import { Abi } from '@sentio/abi-wan-kanabi'
|
8
|
+
import { recursiveCodegen } from '../../core/codegen.js'
|
8
9
|
|
9
10
|
export async function codegen(abisDir: string, outDir: string) {
|
10
11
|
if (!fs.existsSync(abisDir)) {
|
11
12
|
return
|
12
13
|
}
|
13
14
|
|
14
|
-
const numFiles = await
|
15
|
+
const numFiles = await recursiveCodegen(abisDir, outDir, codegenInternal)
|
15
16
|
console.log(chalk.green(`Generated ${numFiles} files for Starknet`))
|
16
17
|
}
|
17
18
|
|
package/src/store/codegen.ts
CHANGED
@@ -162,26 +162,43 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
|
|
162
162
|
const annotations: string[] = []
|
163
163
|
addTypeAnnotations(f.type, annotations)
|
164
164
|
if (isRelationType(f.type)) {
|
165
|
-
fields.push({
|
166
|
-
name: '_' + f.name,
|
167
|
-
type: `Promise<${type}>`,
|
168
|
-
annotations,
|
169
|
-
private: true
|
170
|
-
})
|
171
|
-
methods.push({
|
172
|
-
name: f.name,
|
173
|
-
returnType: `Promise<${type}>`,
|
174
|
-
body: `return this._${f.name}`,
|
175
|
-
annotations: []
|
176
|
-
})
|
177
165
|
const isMany = type.startsWith('Array')
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
166
|
+
|
167
|
+
if (isDerived(f)) {
|
168
|
+
const derivedField = getDerivedField(f)
|
169
|
+
if (isMany) {
|
170
|
+
methods.push({
|
171
|
+
name: f.name,
|
172
|
+
returnType: `Promise<${type}>`,
|
173
|
+
body: `return this.store.list(${elemType(f.type)}, [{field: '${derivedField}', op: '=', value: this.id}])`,
|
174
|
+
annotations: []
|
175
|
+
})
|
176
|
+
} else {
|
177
|
+
methods.push({
|
178
|
+
name: f.name,
|
179
|
+
returnType: `Promise<${type}>`,
|
180
|
+
body: `return this.store.get(${elemType(f.type)}, [{field: '${derivedField}', op: '=', value: this.id}])?.[0]`,
|
181
|
+
annotations: []
|
182
|
+
})
|
183
|
+
}
|
184
|
+
} else {
|
185
|
+
fields.push({
|
186
|
+
name: '_' + f.name,
|
187
|
+
type: `Promise<${type}>`,
|
188
|
+
annotations,
|
189
|
+
private: true
|
190
|
+
})
|
191
|
+
methods.push({
|
192
|
+
name: f.name,
|
193
|
+
returnType: `Promise<${type}>`,
|
194
|
+
body: `return this._${f.name}`,
|
195
|
+
annotations: []
|
196
|
+
})
|
197
|
+
fields.push({
|
198
|
+
name: f.name + 'ID' + (isMany ? 's' : ''),
|
199
|
+
type: isMany ? `Array<ID | undefined>` : `ID`,
|
200
|
+
annotations: []
|
201
|
+
})
|
185
202
|
if (isMany) {
|
186
203
|
methods.push({
|
187
204
|
name: `set${upperFirst(f.name)}`,
|
@@ -317,6 +334,16 @@ function genType(type: GraphQLOutputType, required?: boolean): string {
|
|
317
334
|
}
|
318
335
|
}
|
319
336
|
|
337
|
+
function elemType(type: GraphQLOutputType): GraphQLOutputType {
|
338
|
+
if (isNonNullType(type)) {
|
339
|
+
return elemType(type.ofType)
|
340
|
+
}
|
341
|
+
if (isListType(type)) {
|
342
|
+
return elemType(type.ofType)
|
343
|
+
}
|
344
|
+
return type
|
345
|
+
}
|
346
|
+
|
320
347
|
function genMethod(method: Method) {
|
321
348
|
return `${method.annotations.map((a) => `@${a}`).join('\n')}
|
322
349
|
${method.name}(${method.parameters?.join(', ') ?? ''})${method.returnType ? `: ${method.returnType}` : ''} {
|
@@ -343,3 +370,12 @@ function isEntity(t: GraphQLObjectType) {
|
|
343
370
|
function isDerived(f: GraphQLField<any, any>) {
|
344
371
|
return f.astNode?.directives?.some((d) => d.name.value == 'derivedFrom')
|
345
372
|
}
|
373
|
+
|
374
|
+
function getDerivedField(f: GraphQLField<any, any>) {
|
375
|
+
return (
|
376
|
+
f.astNode?.directives
|
377
|
+
?.find((d) => d.name.value == 'derivedFrom')
|
378
|
+
// @ts-ignore access astNode
|
379
|
+
?.arguments?.find((a) => a.name.value == 'field')?.value?.value
|
380
|
+
)
|
381
|
+
}
|
package/src/store/store.ts
CHANGED
@@ -282,7 +282,9 @@ type CompatibleValue<T, O extends Operators<T>> = O extends ArrayOperators
|
|
282
282
|
? BigDecimal | number
|
283
283
|
: T extends Int
|
284
284
|
? number
|
285
|
-
: T)
|
285
|
+
: T extends () => Promise<any>
|
286
|
+
? ID | string
|
287
|
+
: T)
|
286
288
|
| Nullable<O>
|
287
289
|
|
288
290
|
type Nullable<O> = O extends '=' | '!=' ? null : never
|
package/src/store/types.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { RichStruct, RichValue } from '@sentio/protos'
|
2
2
|
import { BigDecimalConverter, BigIntConverter } from './convert.js'
|
3
|
-
import { getEntityName } from './store.js'
|
3
|
+
import { getEntityName, Store } from './store.js'
|
4
|
+
import { PluginManager } from '@sentio/runtime'
|
4
5
|
|
5
6
|
export type ID = string | Uint8Array
|
6
7
|
export type String = string
|
@@ -29,6 +30,14 @@ export abstract class AbstractEntity {
|
|
29
30
|
const obj = this.toJSON()
|
30
31
|
return `${getEntityName(this)} ${JSON.stringify(obj)}`
|
31
32
|
}
|
33
|
+
|
34
|
+
get store() {
|
35
|
+
const ctx = PluginManager.INSTANCE.dbContextLocalStorage.getStore()
|
36
|
+
if (!ctx) {
|
37
|
+
throw new Error('Store not found in context')
|
38
|
+
}
|
39
|
+
return new Store(ctx)
|
40
|
+
}
|
32
41
|
}
|
33
42
|
|
34
43
|
function toJSValue(value: RichValue): any {
|
@@ -7,6 +7,7 @@ import { SuiCodegen as BaseSuiCodegen } from '@typemove/sui/codegen'
|
|
7
7
|
import path, { join } from 'path'
|
8
8
|
import { SharedNetworkCodegen } from '../../move/shared-network-codegen.js'
|
9
9
|
import { getRpcEndpoint, SuiNetwork } from '../network.js'
|
10
|
+
import { recursiveCodegen } from '../../core/codegen.js'
|
10
11
|
|
11
12
|
export async function codegen(
|
12
13
|
abisDir: string,
|
@@ -97,8 +98,17 @@ const TESTNET_CODEGEN = new SuiNetworkCodegen(SuiNetwork.TEST_NET)
|
|
97
98
|
|
98
99
|
class SuiCodegen {
|
99
100
|
async generate(srcDir: string, outputDir: string, builtin = false): Promise<number> {
|
100
|
-
|
101
|
-
const
|
102
|
-
|
101
|
+
let numFiles = 0
|
102
|
+
const generators: [string, SuiNetworkCodegen][] = [
|
103
|
+
['', MAINNET_CODEGEN],
|
104
|
+
['testnet', TESTNET_CODEGEN]
|
105
|
+
]
|
106
|
+
|
107
|
+
for (const [network, gen] of generators) {
|
108
|
+
numFiles += await recursiveCodegen(path.join(srcDir, network), path.join(outputDir, network), (src, dst) =>
|
109
|
+
gen.generate(src, dst, builtin)
|
110
|
+
)
|
111
|
+
}
|
112
|
+
return numFiles
|
103
113
|
}
|
104
114
|
}
|