@sentio/sdk 2.40.1-rc.3 → 2.40.1-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +5 -5
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc1155-processor.js +3 -3
- package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20-processor.js +10 -10
- package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.js +3 -3
- package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc721-processor.js +5 -5
- package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
- package/lib/eth/builtin/internal/weth9-processor.js +4 -4
- package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
- package/lib/eth/codegen/types.js +1 -1
- package/lib/eth/codegen/types.js.map +1 -1
- package/lib/store/cache.d.ts +0 -3
- package/lib/store/cache.d.ts.map +1 -1
- package/lib/store/cache.js.map +1 -1
- package/lib/store/codegen.d.ts.map +1 -1
- package/lib/store/codegen.js +51 -34
- package/lib/store/codegen.js.map +1 -1
- package/lib/store/store.d.ts +3 -3
- package/lib/store/store.d.ts.map +1 -1
- package/lib/store/store.js +2 -2
- package/lib/store/store.js.map +1 -1
- package/lib/store/types.d.ts +6 -0
- package/lib/store/types.d.ts.map +1 -1
- package/lib/store/types.js +49 -1
- package/lib/store/types.js.map +1 -1
- package/package.json +3 -3
- package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +5 -5
- package/src/eth/builtin/internal/erc1155-processor.ts +3 -3
- package/src/eth/builtin/internal/erc20-processor.ts +10 -10
- package/src/eth/builtin/internal/erc20bytes-processor.ts +3 -3
- package/src/eth/builtin/internal/erc721-processor.ts +5 -5
- package/src/eth/builtin/internal/weth9-processor.ts +4 -4
- package/src/eth/codegen/types.ts +1 -1
- package/src/store/cache.ts +0 -4
- package/src/store/codegen.ts +53 -34
- package/src/store/store.ts +5 -5
- package/src/store/types.ts +57 -0
@@ -194,10 +194,10 @@ const templateContract = EACAggregatorProxy__factory.connect(
|
|
194
194
|
);
|
195
195
|
|
196
196
|
const iface = new Interface([
|
197
|
-
"function acceptOwnership()
|
197
|
+
"function acceptOwnership() returns ()",
|
198
198
|
"function accessController() view returns (address)",
|
199
199
|
"function aggregator() view returns (address)",
|
200
|
-
"function confirmAggregator(address _aggregator)
|
200
|
+
"function confirmAggregator(address _aggregator) returns ()",
|
201
201
|
"function decimals() view returns (uint8)",
|
202
202
|
"function description() view returns (string)",
|
203
203
|
"function getAnswer(uint256 _roundId) view returns (int256)",
|
@@ -210,12 +210,12 @@ const iface = new Interface([
|
|
210
210
|
"function owner() view returns (address)",
|
211
211
|
"function phaseAggregators(uint16) view returns (address)",
|
212
212
|
"function phaseId() view returns (uint16)",
|
213
|
-
"function proposeAggregator(address _aggregator)
|
213
|
+
"function proposeAggregator(address _aggregator) returns ()",
|
214
214
|
"function proposedAggregator() view returns (address)",
|
215
215
|
"function proposedGetRoundData(uint80 _roundId) view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)",
|
216
216
|
"function proposedLatestRoundData() view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)",
|
217
|
-
"function setController(address _accessController)
|
218
|
-
"function transferOwnership(address _to)
|
217
|
+
"function setController(address _accessController) returns ()",
|
218
|
+
"function transferOwnership(address _to) returns ()",
|
219
219
|
"function version() view returns (uint256)",
|
220
220
|
]);
|
221
221
|
|
@@ -125,9 +125,9 @@ const iface = new Interface([
|
|
125
125
|
"function balanceOf(address account, uint256 id) view returns (uint256)",
|
126
126
|
"function balanceOfBatch(address[] accounts, uint256[] ids) view returns (uint256[])",
|
127
127
|
"function isApprovedForAll(address account, address operator) view returns (bool)",
|
128
|
-
"function safeBatchTransferFrom(address from, address to, uint256[] ids, uint256[] amounts, bytes data)
|
129
|
-
"function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes data)
|
130
|
-
"function setApprovalForAll(address operator, bool approved)
|
128
|
+
"function safeBatchTransferFrom(address from, address to, uint256[] ids, uint256[] amounts, bytes data) returns ()",
|
129
|
+
"function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes data) returns ()",
|
130
|
+
"function setApprovalForAll(address operator, bool approved) returns ()",
|
131
131
|
"function supportsInterface(bytes4 interfaceId) view returns (bool)",
|
132
132
|
"function uri(uint256 id) view returns (string)",
|
133
133
|
]);
|
@@ -169,23 +169,23 @@ const templateContract = ERC20__factory.connect("0x0", DummyProvider);
|
|
169
169
|
|
170
170
|
const iface = new Interface([
|
171
171
|
"function allowance(address owner, address spender) view returns (uint256)",
|
172
|
-
"function approve(address spender, uint256 amount)
|
172
|
+
"function approve(address spender, uint256 amount) returns (bool)",
|
173
173
|
"function balanceOf(address account) view returns (uint256)",
|
174
|
-
"function burn(uint256 amount)
|
175
|
-
"function burnFrom(address account, uint256 amount)
|
174
|
+
"function burn(uint256 amount) returns ()",
|
175
|
+
"function burnFrom(address account, uint256 amount) returns ()",
|
176
176
|
"function decimals() view returns (uint8)",
|
177
|
-
"function decreaseAllowance(address spender, uint256 subtractedValue)
|
178
|
-
"function increaseAllowance(address spender, uint256 addedValue)
|
177
|
+
"function decreaseAllowance(address spender, uint256 subtractedValue) returns (bool)",
|
178
|
+
"function increaseAllowance(address spender, uint256 addedValue) returns (bool)",
|
179
179
|
"function locker() view returns (address)",
|
180
180
|
"function name() view returns (string)",
|
181
181
|
"function owner() view returns (address)",
|
182
|
-
"function renounceOwnership()
|
183
|
-
"function setLocker(address _locker)
|
182
|
+
"function renounceOwnership() returns ()",
|
183
|
+
"function setLocker(address _locker) returns ()",
|
184
184
|
"function symbol() view returns (string)",
|
185
185
|
"function totalSupply() view returns (uint256)",
|
186
|
-
"function transfer(address recipient, uint256 amount)
|
187
|
-
"function transferFrom(address sender, address recipient, uint256 amount)
|
188
|
-
"function transferOwnership(address newOwner)
|
186
|
+
"function transfer(address recipient, uint256 amount) returns (bool)",
|
187
|
+
"function transferFrom(address sender, address recipient, uint256 amount) returns (bool)",
|
188
|
+
"function transferOwnership(address newOwner) returns ()",
|
189
189
|
]);
|
190
190
|
|
191
191
|
export class ERC20ContractView extends ContractView<ERC20> {
|
@@ -101,13 +101,13 @@ const templateContract = ERC20Bytes__factory.connect("0x0", DummyProvider);
|
|
101
101
|
|
102
102
|
const iface = new Interface([
|
103
103
|
"function name() view returns (bytes32)",
|
104
|
-
"function approve(address spender, uint256 value)
|
104
|
+
"function approve(address spender, uint256 value) returns (bool)",
|
105
105
|
"function totalSupply() view returns (uint256)",
|
106
|
-
"function transferFrom(address from, address to, uint256 value)
|
106
|
+
"function transferFrom(address from, address to, uint256 value) returns (bool)",
|
107
107
|
"function decimals() view returns (uint8)",
|
108
108
|
"function balanceOf(address who) view returns (uint256)",
|
109
109
|
"function symbol() view returns (bytes32)",
|
110
|
-
"function transfer(address to, uint256 value)
|
110
|
+
"function transfer(address to, uint256 value) returns (bool)",
|
111
111
|
"function allowance(address owner, address spender) view returns (uint256)",
|
112
112
|
]);
|
113
113
|
|
@@ -152,20 +152,20 @@ export type TransferFromCallTrace = TypedCallTrace<
|
|
152
152
|
const templateContract = ERC721__factory.connect("0x0", DummyProvider);
|
153
153
|
|
154
154
|
const iface = new Interface([
|
155
|
-
"function approve(address to, uint256 tokenId)
|
155
|
+
"function approve(address to, uint256 tokenId) returns ()",
|
156
156
|
"function totalSupply() view returns (uint256)",
|
157
157
|
"function balanceOf(address owner) view returns (uint256 balance)",
|
158
158
|
"function getApproved(uint256 tokenId) view returns (address operator)",
|
159
159
|
"function isApprovedForAll(address owner, address operator) view returns (bool)",
|
160
160
|
"function name() view returns (string)",
|
161
161
|
"function ownerOf(uint256 tokenId) view returns (address owner)",
|
162
|
-
"function safeTransferFrom(address from, address to, uint256 tokenId)
|
163
|
-
"function safeTransferFrom(address from, address to, uint256 tokenId, bytes data)
|
164
|
-
"function setApprovalForAll(address operator, bool _approved)
|
162
|
+
"function safeTransferFrom(address from, address to, uint256 tokenId) returns ()",
|
163
|
+
"function safeTransferFrom(address from, address to, uint256 tokenId, bytes data) returns ()",
|
164
|
+
"function setApprovalForAll(address operator, bool _approved) returns ()",
|
165
165
|
"function supportsInterface(bytes4 interfaceId) view returns (bool)",
|
166
166
|
"function symbol() view returns (string)",
|
167
167
|
"function tokenURI(uint256 tokenId) view returns (string)",
|
168
|
-
"function transferFrom(address from, address to, uint256 tokenId)
|
168
|
+
"function transferFrom(address from, address to, uint256 tokenId) returns ()",
|
169
169
|
]);
|
170
170
|
|
171
171
|
export class ERC721ContractView extends ContractView<ERC721> {
|
@@ -110,14 +110,14 @@ const templateContract = WETH9__factory.connect("0x0", DummyProvider);
|
|
110
110
|
|
111
111
|
const iface = new Interface([
|
112
112
|
"function name() view returns (string)",
|
113
|
-
"function approve(address guy, uint256 wad)
|
113
|
+
"function approve(address guy, uint256 wad) returns (bool)",
|
114
114
|
"function totalSupply() view returns (uint256)",
|
115
|
-
"function transferFrom(address src, address dst, uint256 wad)
|
116
|
-
"function withdraw(uint256 wad)
|
115
|
+
"function transferFrom(address src, address dst, uint256 wad) returns (bool)",
|
116
|
+
"function withdraw(uint256 wad) returns ()",
|
117
117
|
"function decimals() view returns (uint8)",
|
118
118
|
"function balanceOf(address) view returns (uint256)",
|
119
119
|
"function symbol() view returns (string)",
|
120
|
-
"function transfer(address dst, uint256 wad)
|
120
|
+
"function transfer(address dst, uint256 wad) returns (bool)",
|
121
121
|
"function deposit() payable returns ()",
|
122
122
|
"function allowance(address, address) view returns (uint256)",
|
123
123
|
]);
|
package/src/eth/codegen/types.ts
CHANGED
@@ -50,7 +50,7 @@ export function getFullSignatureForFunction(fn: FunctionDeclaration): string {
|
|
50
50
|
}
|
51
51
|
|
52
52
|
export function getFullSignatureWithOutputForFn(fn: FunctionDeclaration) {
|
53
|
-
return `${fn.name}(${fn.inputs.map((i) => getArgumentForSignature(i)).join(', ')}) ${fn.stateMutability}
|
53
|
+
return `${fn.name}(${fn.inputs.map((i) => getArgumentForSignature(i)).join(', ')}) ${fn.stateMutability != 'nonpayable' ? fn.stateMutability + ' ' : ''}returns (${fn.outputs
|
54
54
|
.map((i) => getOutputArgumentForSignature(i))
|
55
55
|
.filter((s) => s != '')
|
56
56
|
.join(', ')})`
|
package/src/store/cache.ts
CHANGED
package/src/store/codegen.ts
CHANGED
@@ -34,6 +34,7 @@ interface Class {
|
|
34
34
|
name: string
|
35
35
|
fields: Field[]
|
36
36
|
annotations: string[]
|
37
|
+
parent?: string
|
37
38
|
interfaces: string[]
|
38
39
|
}
|
39
40
|
|
@@ -98,7 +99,7 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
|
|
98
99
|
},
|
99
100
|
{
|
100
101
|
module: '@sentio/sdk/store',
|
101
|
-
types: ['Entity', 'Required', 'One', 'Many', 'Column', 'ListColumn']
|
102
|
+
types: ['Entity', 'Required', 'One', 'Many', 'Column', 'ListColumn', 'AbstractEntity']
|
102
103
|
},
|
103
104
|
{
|
104
105
|
module: '@sentio/bigdecimal',
|
@@ -134,44 +135,60 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
|
|
134
135
|
})
|
135
136
|
}
|
136
137
|
}
|
138
|
+
|
137
139
|
for (const t of Object.values(schema.getTypeMap())) {
|
138
140
|
if (t.name.startsWith('__')) {
|
139
141
|
continue
|
140
142
|
}
|
141
143
|
|
142
144
|
if (t instanceof GraphQLObjectType) {
|
143
|
-
|
144
|
-
|
145
|
-
const
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
145
|
+
if (isEntity(t)) {
|
146
|
+
const fields: Field[] = []
|
147
|
+
for (const f of Object.values(t.getFields())) {
|
148
|
+
const type = genType(f.type)
|
149
|
+
const annotations: string[] = []
|
150
|
+
addTypeAnnotations(f.type, annotations)
|
151
|
+
if (isRelationType(f.type)) {
|
152
|
+
fields.push({
|
153
|
+
name: f.name,
|
154
|
+
type: `Promise<${type}>`,
|
155
|
+
annotations
|
156
|
+
})
|
157
|
+
const isMany = type.startsWith('Array')
|
158
|
+
fields.push({
|
159
|
+
name: f.name + 'ID' + (isMany ? 's' : ''),
|
160
|
+
type: isMany ? `Array<ID | undefined>` : `ID`,
|
161
|
+
annotations: []
|
162
|
+
})
|
163
|
+
} else {
|
164
|
+
fields.push({
|
165
|
+
name: f.name,
|
166
|
+
optional: !f.type.toString().endsWith('!'),
|
167
|
+
type: type.replace(' | undefined', ''),
|
168
|
+
annotations
|
169
|
+
})
|
170
|
+
}
|
171
|
+
}
|
172
|
+
classes.push({
|
173
|
+
name: t.name,
|
174
|
+
fields,
|
175
|
+
annotations: [`@Entity("${t.name}")`],
|
176
|
+
parent: 'AbstractEntity',
|
177
|
+
interfaces: t.getInterfaces().map((i) => i.name)
|
178
|
+
})
|
179
|
+
} else {
|
180
|
+
classes.push({
|
181
|
+
name: t.name,
|
182
|
+
fields: Object.values(t.getFields()).map((f) => ({
|
162
183
|
name: f.name,
|
163
184
|
optional: !f.type.toString().endsWith('!'),
|
164
|
-
type: type.replace(' | undefined', ''),
|
165
|
-
annotations
|
166
|
-
})
|
167
|
-
|
185
|
+
type: genType(f.type).replace(' | undefined', ''),
|
186
|
+
annotations: []
|
187
|
+
})),
|
188
|
+
annotations: [],
|
189
|
+
interfaces: t.getInterfaces().map((i) => i.name)
|
190
|
+
})
|
168
191
|
}
|
169
|
-
classes.push({
|
170
|
-
name: t.name,
|
171
|
-
fields,
|
172
|
-
annotations: [`@Entity("${t.name}")`],
|
173
|
-
interfaces: t.getInterfaces().map((i) => i.name)
|
174
|
-
})
|
175
192
|
}
|
176
193
|
}
|
177
194
|
|
@@ -201,13 +218,11 @@ ${classes
|
|
201
218
|
.map(
|
202
219
|
(c) => `
|
203
220
|
${c.annotations.join('\n')}
|
204
|
-
export class ${c.name} ${c.interfaces.length > 0 ? `implements ${c.interfaces.join(', ')}` : ''} {
|
221
|
+
export class ${c.name} ${c.parent ? `extends ${c.parent}` : ''} ${c.interfaces.length > 0 ? `implements ${c.interfaces.join(', ')}` : ''} {
|
205
222
|
${c.fields
|
206
223
|
.map((f) => `${f.annotations.map((a) => `\n\t${a}`).join('')}\n\t${f.name}${f.optional ? '?' : ''}: ${f.type}`)
|
207
224
|
.join('\n')}
|
208
|
-
|
209
|
-
constructor(data: Partial<${c.name}>) {}
|
210
|
-
|
225
|
+
${c.annotations.some((a) => a.startsWith('@Entity')) ? `constructor(data: Partial<${c.name}>) {super()}` : ''}
|
211
226
|
}`
|
212
227
|
)
|
213
228
|
.join('\n')}
|
@@ -256,3 +271,7 @@ function isRelationType(type: GraphQLOutputType): boolean {
|
|
256
271
|
return false
|
257
272
|
}
|
258
273
|
}
|
274
|
+
|
275
|
+
function isEntity(t: GraphQLObjectType) {
|
276
|
+
return t.astNode?.directives?.some((d) => d.name.value == 'entity')
|
277
|
+
}
|
package/src/store/store.ts
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
import { StoreContext } from './context.js'
|
2
2
|
import { DatabaseSchema } from '../core/index.js'
|
3
3
|
import { BigDecimal } from '@sentio/bigdecimal'
|
4
|
-
import { Bytes, Float, ID, Int, Timestamp } from './types.js'
|
4
|
+
import { AbstractEntity as Entity, Bytes, Float, ID, Int, Timestamp } from './types.js'
|
5
5
|
import type { DBRequest, Entity as EntityStruct, RichValue } from '@sentio/protos'
|
6
6
|
import { DBRequest_DBOperator, DBResponse } from '@sentio/protos'
|
7
7
|
import { toBigInteger } from './convert.js'
|
8
8
|
import { PluginManager } from '@sentio/runtime'
|
9
9
|
import { Cursor } from './cursor.js'
|
10
|
-
import {
|
10
|
+
import { LocalCache } from './cache.js'
|
11
11
|
|
12
12
|
export interface EntityClass<T> {
|
13
13
|
new (data: Partial<T>): T
|
14
14
|
}
|
15
15
|
|
16
|
-
function getEntityName<T>(entity: EntityClass<T> | T | string): string {
|
16
|
+
export function getEntityName<T>(entity: EntityClass<T> | T | string): string {
|
17
17
|
if (entity == null) {
|
18
18
|
throw new Error("can't figure out entityName from undefined")
|
19
19
|
}
|
@@ -182,7 +182,7 @@ export class Store {
|
|
182
182
|
|
183
183
|
async list<T extends Entity, P extends keyof T, O extends Operators<T[P]>>(
|
184
184
|
entity: EntityClass<T>,
|
185
|
-
filters
|
185
|
+
filters?: ListFilter<T, P, O>[],
|
186
186
|
cursor?: Cursor
|
187
187
|
) {
|
188
188
|
if (cursor) {
|
@@ -191,7 +191,7 @@ export class Store {
|
|
191
191
|
return response.entityList?.entities.map((data) => this.newEntity(entity, data)) || []
|
192
192
|
}
|
193
193
|
// TODO Array.fromAsync when upgrade to node 22
|
194
|
-
return this.fromAsync(this.listIterator(entity, filters))
|
194
|
+
return this.fromAsync(this.listIterator(entity, filters ?? []))
|
195
195
|
}
|
196
196
|
|
197
197
|
private async fromAsync<T>(gen: AsyncIterable<T>): Promise<T[]> {
|
package/src/store/types.ts
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
import { RichStruct, RichValue } from '@sentio/protos'
|
2
|
+
import { BigDecimalConverter, BigIntConverter } from './convert.js'
|
3
|
+
import { getEntityName } from './store.js'
|
4
|
+
|
1
5
|
export type ID = string | Uint8Array
|
2
6
|
export type String = string
|
3
7
|
export type Int = number
|
@@ -6,3 +10,56 @@ export type Boolean = boolean
|
|
6
10
|
export type Timestamp = Date
|
7
11
|
export type Bytes = Uint8Array
|
8
12
|
export type BigInt = bigint
|
13
|
+
|
14
|
+
export abstract class AbstractEntity {
|
15
|
+
abstract id: ID
|
16
|
+
private readonly _data: RichStruct
|
17
|
+
|
18
|
+
toJSON() {
|
19
|
+
const obj: any = {}
|
20
|
+
|
21
|
+
for (const [field, value] of Object.entries(this._data.fields)) {
|
22
|
+
obj[field] = toJSValue(value)
|
23
|
+
}
|
24
|
+
return obj
|
25
|
+
}
|
26
|
+
|
27
|
+
toString() {
|
28
|
+
const obj = this.toJSON()
|
29
|
+
return `${getEntityName(this)} ${JSON.stringify(obj)}`
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
function toJSValue(value: RichValue): any {
|
34
|
+
if (value.nullValue) {
|
35
|
+
return null
|
36
|
+
}
|
37
|
+
if (value.bytesValue) {
|
38
|
+
return value.bytesValue
|
39
|
+
}
|
40
|
+
if (value.stringValue) {
|
41
|
+
return value.stringValue
|
42
|
+
}
|
43
|
+
if (value.bigdecimalValue) {
|
44
|
+
return BigDecimalConverter.to(value)
|
45
|
+
}
|
46
|
+
if (value.bigintValue) {
|
47
|
+
return BigIntConverter.to(value)
|
48
|
+
}
|
49
|
+
if (value.boolValue) {
|
50
|
+
return value.boolValue
|
51
|
+
}
|
52
|
+
if (value.timestampValue) {
|
53
|
+
return value.timestampValue
|
54
|
+
}
|
55
|
+
if (value.floatValue) {
|
56
|
+
return value.floatValue
|
57
|
+
}
|
58
|
+
if (value.intValue) {
|
59
|
+
return value.intValue
|
60
|
+
}
|
61
|
+
if (value.listValue) {
|
62
|
+
return value.listValue.values.map(toJSValue)
|
63
|
+
}
|
64
|
+
throw new Error('Unknown value type:' + JSON.stringify(value))
|
65
|
+
}
|