Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions examples/example-subgraph/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
keytar "^4.6.0"

"@graphprotocol/graph-ts@git+http://github.com/graphprotocol/graph-ts#master":
version "0.13.0"
resolved "git+http://github.com/graphprotocol/graph-ts#746a89d8c394fd19dfb90acdc6903809be62f20c"
version "0.14.0"
resolved "git+http://github.com/graphprotocol/graph-ts#3238281c89c56d3bed24dba4ae61f04f1173b18d"
dependencies:
assemblyscript "https://github.com/AssemblyScript/assemblyscript#36040d5b5312f19a025782b5e36663823494c2f3"

"@protobufjs/utf8@^1.1.0":
version "1.1.0"
resolved "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=

"@types/node@^10.3.5":
Expand Down Expand Up @@ -244,7 +244,7 @@ axios@^0.18.0:

balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=

base-x@3.0.4:
Expand Down Expand Up @@ -298,7 +298,7 @@ binary-extensions@^1.0.0:

binaryen@77.0.0-nightly.20190407:
version "77.0.0-nightly.20190407"
resolved "https://registry.npmjs.org/binaryen/-/binaryen-77.0.0-nightly.20190407.tgz#fbe4f8ba0d6bd0809a84eb519d2d5b5ddff3a7d1"
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-77.0.0-nightly.20190407.tgz#fbe4f8ba0d6bd0809a84eb519d2d5b5ddff3a7d1"
integrity sha512-1mxYNvQ0xywMe582K7V6Vo2zzhZZxMTeGHH8aE/+/AND8f64D8Q1GThVY3RVRwGY/4p+p95ccw9Xbw2ovFXRIg==

bindings@^1.3.0, bindings@^1.5.0:
Expand Down Expand Up @@ -354,7 +354,7 @@ borc@^2.1.0:

brace-expansion@^1.1.7:
version "1.1.11"
resolved "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==
dependencies:
balanced-match "^1.0.0"
Expand Down Expand Up @@ -420,7 +420,7 @@ buffer-fill@^1.0.0:

buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==

buffer-xor@^1.0.3:
Expand Down Expand Up @@ -629,7 +629,7 @@ component-emitter@^1.2.1:

concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=

concat-stream@^2.0.0:
Expand Down Expand Up @@ -1077,7 +1077,7 @@ fs-minipass@^1.2.5:

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=

fsevents@^1.2.7:
Expand Down Expand Up @@ -1322,13 +1322,18 @@ import-fresh@^2.0.0:

inflight@^1.0.4:
version "1.0.6"
resolved "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=
dependencies:
once "^1.3.0"
wrappy "1"

inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.3:
inherits@2:
version "2.0.4"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==

inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.3:
version "2.0.3"
resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=
Expand Down Expand Up @@ -1911,7 +1916,7 @@ log-symbols@^2.2.0:

long@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==

looper@^3.0.0:
Expand Down Expand Up @@ -2318,7 +2323,7 @@ onetime@^2.0.0:

opencollective-postinstall@^2.0.0:
version "2.0.2"
resolved "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.2.tgz#5657f1bede69b6e33a45939b061eb53d3c6c3a89"
resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.2.tgz#5657f1bede69b6e33a45939b061eb53d3c6c3a89"
integrity sha512-pVOEP16TrAO2/fjej1IdOyupJY8KDUM1CvsaScRbw6oddvpQoOfGk4ywha0HKKVAD6RkW4x6Q+tNBwhf3Bgpuw==

optimist@~0.3.5:
Expand Down Expand Up @@ -2383,7 +2388,7 @@ path-dirname@^1.0.0:

path-is-absolute@^1.0.0:
version "1.0.1"
resolved "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=

path-key@^2.0.0, path-key@^2.0.1:
Expand Down Expand Up @@ -2895,9 +2900,9 @@ source-map-resolve@^0.5.0:
urix "^0.1.0"

source-map-support@^0.5.11:
version "0.5.12"
resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.12.tgz#b4f3b10d51857a5af0138d3ce8003b201613d599"
integrity sha512-4h2Pbvyy15EE02G+JOZpUCmqWJuqrs+sEkzewTm++BPi7Hvn/HwcqLAcNxYAyI0x13CpPPn+kMjl+hplXMHITQ==
version "0.5.13"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.13.tgz#31b24a9c2e73c2de85066c0feb7d44767ed52932"
integrity sha512-SHSKFHadjVA5oR4PPqhtAVdcBWwRYVd6g6cAXnIbRiIwc2EhPrTuKUBdSLvlEKyIP3GCf89fltvcZiP9MMFA1w==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
Expand All @@ -2914,7 +2919,7 @@ source-map@^0.5.6:

source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==

split-string@^3.0.1, split-string@^3.0.2:
Expand Down Expand Up @@ -3292,7 +3297,7 @@ wordwrap@~0.0.2:

wrappy@1:
version "1.0.2"
resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=

xtend@^4.0.0, xtend@~4.0.1:
Expand Down
185 changes: 98 additions & 87 deletions src/codegen/abi.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = class AbiCodeGenerator {
'Bytes',
'Address',
'BigInt',
'CallResult',
],
'@graphprotocol/graph-ts',
),
Expand Down Expand Up @@ -257,6 +258,10 @@ module.exports = class AbiCodeGenerator {
}
}

_tupleTypeName(inputOrOutput, index, parentClass, parentType) {
return this._generateTupleType(inputOrOutput, index, parentClass, parentType, '').name
}

_generateTupleType(inputOrOutput, index, parentClass, parentType, parentField) {
let name = inputOrOutput.get('name')
if (name === undefined || name === null || name === '') {
Expand Down Expand Up @@ -370,23 +375,19 @@ module.exports = class AbiCodeGenerator {
tsCodegen.param(
`value${index}`,
output.get('type') === 'tuple'
? this._generateTupleType(
? this._tupleTypeName(
output,
index,
tupleResultParentType,
this.abi.name,
'',
).name
)
: util.isTupleArrayType(output.get('type'))
? `Array<${
this._generateTupleType(
output,
index,
tupleResultParentType,
this.abi.name,
'',
).name
}>`
? `Array<${this._tupleTypeName(
output,
index,
tupleResultParentType,
this.abi.name,
)}>`
: typesCodegen.ascTypeForEthereum(output.get('type')),
),
),
Expand Down Expand Up @@ -496,83 +497,93 @@ module.exports = class AbiCodeGenerator {

// Generate and add a method that implements calling the function on
// the smart contract
let params = inputs.map((input, index) =>
tsCodegen.param(
input.get('name'),
input.get('type') === 'tuple'
? this._tupleTypeName(input, index, tupleInputParentType, this.abi.name)
: util.isTupleArrayType(input.get('type'))
? `Array<${this._tupleTypeName(input, index, tupleInputParentType)}>`
: typesCodegen.ascTypeForEthereum(input.get('type')),
),
)

let superInputs = `
'${fnName}',
[${
inputs.size > 0
? inputs
.map(input =>
typesCodegen.ethereumValueFromAsc(input.get('name'), input.get('type')),
)
.map(coercion => coercion.toString())
.join(', ')
: ''
}]`

let methodCallBody = isTry =>
`
${
isTry
? `
let result = super.tryCall(${superInputs})
if (result.reverted) {
return new CallResult()
}
let value = result.value
return CallResult.fromValue(`
: `
let result = super.call(${superInputs})

return (`
}
${
simpleReturnType
? typesCodegen.ethereumValueToAsc(
isTry ? 'value[0]' : 'result[0]',
outputs.get(0).get('type'),
util.isTupleArrayType(outputs.get(0).get('type'))
? this._tupleTypeName(
outputs.get(0),
0,
tupleResultParentType,
this.abi.name,
)
: '',
)
: `new ${returnType.name}(
${outputs
.map(
(output, index) =>
`${typesCodegen.ethereumValueToAsc(
isTry ? `value[${index}]` : `result[${index}]`,
output.get('type'),
)} ${
output.get('type') === 'tuple'
? 'as ' +
this._tupleTypeName(
output,
index,
tupleResultParentType,
this.abi.name,
)
: ''
}`,
)
.join(', ')}
)`
} ${outputs.get(0).get('type') === 'tuple' ? 'as ' + returnType : ''} )`

// Generate method with an without `try_`.
klass.addMethod(
tsCodegen.method(fnAlias, params, returnType, methodCallBody(false)),
)
klass.addMethod(
tsCodegen.method(
fnAlias,
inputs.map((input, index) =>
tsCodegen.param(
input.get('name'),
input.get('type') === 'tuple'
? this._generateTupleType(
input,
index,
tupleInputParentType,
this.abi.name,
'',
).name
: util.isTupleArrayType(input.get('type'))
? `Array<${
this._generateTupleType(input, index, tupleInputParentType, '').name
}>`
: typesCodegen.ascTypeForEthereum(input.get('type')),
),
),
returnType,
`
let result = super.call(
'${fnName}',
[${
inputs.size > 0
? inputs
.map(input =>
typesCodegen.ethereumValueFromAsc(
input.get('name'),
input.get('type'),
),
)
.map(coercion => coercion.toString())
.join(', ')
: ''
}]
);
return ${
simpleReturnType
? typesCodegen.ethereumValueToAsc(
'result[0]',
outputs.get(0).get('type'),
util.isTupleArrayType(outputs.get(0).get('type'))
? this._generateTupleType(
outputs.get(0),
0,
tupleResultParentType,
this.abi.name,
'',
).name
: '',
)
: `new ${returnType.name}(
${outputs
.map(
(output, index) =>
`${typesCodegen.ethereumValueToAsc(
`result[${index}]`,
output.get('type'),
)} ${
output.get('type') === 'tuple'
? 'as ' +
this._generateTupleType(
output,
index,
tupleResultParentType,
this.abi.name,
'',
).name
: ''
}`,
)
.join(', ')}
)`
} ${outputs.get(0).get('type') === 'tuple' ? 'as ' + returnType : ''};`,
'try_' + fnAlias,
params,
'CallResult<' + returnType + '>',
methodCallBody(true),
),
)
})
Expand Down
Loading