Skip to content

Commit 6ba30de

Browse files
authored
Merge pull request #390 from identity-com/feature/eth-populateTransaction
Ethereum: Expose populateTransaction on eth gatewayTs.
2 parents b6800a5 + 618260b commit 6ba30de

File tree

9 files changed

+156
-29
lines changed

9 files changed

+156
-29
lines changed

ethereum/gatekeeper-cli/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ $ npm install -g @identity.com/gateway-eth-cli
7878
$ gateway-eth COMMAND
7979
running command...
8080
$ gateway-eth (--version)
81-
@identity.com/gateway-eth-cli/0.0.10 darwin-arm64 node-v16.17.1
81+
@identity.com/gateway-eth-cli/0.0.11 darwin-arm64 node-v16.17.1
8282
$ gateway-eth --help [COMMAND]
8383
USAGE
8484
$ gateway-eth COMMAND
@@ -154,7 +154,7 @@ EXAMPLES
154154
$ gateway-eth add-gatekeeper 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123
155155
```
156156

157-
_See code: [dist/commands/add-gatekeeper.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.10/dist/commands/add-gatekeeper.ts)_
157+
_See code: [dist/commands/add-gatekeeper.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.11/dist/commands/add-gatekeeper.ts)_
158158

159159
## `gateway-eth add-network-authority ADDRESS`
160160

@@ -207,7 +207,7 @@ EXAMPLES
207207
$ gateway-eth add-network-authority 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123
208208
```
209209

210-
_See code: [dist/commands/add-network-authority.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.10/dist/commands/add-network-authority.ts)_
210+
_See code: [dist/commands/add-network-authority.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.11/dist/commands/add-network-authority.ts)_
211211

212212
## `gateway-eth create-gatekeeper-network ID NAME`
213213

@@ -258,7 +258,7 @@ EXAMPLES
258258
$ gateway-eth create-gatekeeper-network <name> <number>
259259
```
260260

261-
_See code: [dist/commands/create-gatekeeper-network.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.10/dist/commands/create-gatekeeper-network.ts)_
261+
_See code: [dist/commands/create-gatekeeper-network.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.11/dist/commands/create-gatekeeper-network.ts)_
262262

263263
## `gateway-eth freeze ADDRESS`
264264

@@ -311,7 +311,7 @@ EXAMPLES
311311
$ gateway-eth freeze 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123
312312
```
313313

314-
_See code: [dist/commands/freeze.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.10/dist/commands/freeze.ts)_
314+
_See code: [dist/commands/freeze.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.11/dist/commands/freeze.ts)_
315315

316316
## `gateway-eth get-gatekeeper-network ID`
317317

@@ -348,7 +348,7 @@ EXAMPLES
348348
$ gateway-eth get-gatekeeper-network <number>
349349
```
350350

351-
_See code: [dist/commands/get-gatekeeper-network.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.10/dist/commands/get-gatekeeper-network.ts)_
351+
_See code: [dist/commands/get-gatekeeper-network.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.11/dist/commands/get-gatekeeper-network.ts)_
352352

353353
## `gateway-eth get-token ADDRESS`
354354

@@ -391,7 +391,7 @@ EXAMPLES
391391
$ gateway-eth get 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123
392392
```
393393

394-
_See code: [dist/commands/get-token.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.10/dist/commands/get-token.ts)_
394+
_See code: [dist/commands/get-token.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.11/dist/commands/get-token.ts)_
395395

396396
## `gateway-eth help [COMMAND]`
397397

@@ -472,7 +472,7 @@ EXAMPLES
472472
$ gateway-eth issue 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123
473473
```
474474

475-
_See code: [dist/commands/issue.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.10/dist/commands/issue.ts)_
475+
_See code: [dist/commands/issue.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.11/dist/commands/issue.ts)_
476476

477477
## `gateway-eth listen ADDRESS`
478478

@@ -512,7 +512,7 @@ EXAMPLES
512512
$ gateway-eth listen 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123
513513
```
514514

515-
_See code: [dist/commands/listen.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.10/dist/commands/listen.ts)_
515+
_See code: [dist/commands/listen.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.11/dist/commands/listen.ts)_
516516

517517
## `gateway-eth refresh ADDRESS [EXPIRY]`
518518

@@ -566,7 +566,7 @@ EXAMPLES
566566
$ gateway-eth refresh 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 60 -n 123
567567
```
568568

569-
_See code: [dist/commands/refresh.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.10/dist/commands/refresh.ts)_
569+
_See code: [dist/commands/refresh.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.11/dist/commands/refresh.ts)_
570570

571571
## `gateway-eth remove-gatekeeper ADDRESS`
572572

@@ -619,7 +619,7 @@ EXAMPLES
619619
$ gateway-eth remove-gatekeeper 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123
620620
```
621621

622-
_See code: [dist/commands/remove-gatekeeper.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.10/dist/commands/remove-gatekeeper.ts)_
622+
_See code: [dist/commands/remove-gatekeeper.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.11/dist/commands/remove-gatekeeper.ts)_
623623

624624
## `gateway-eth remove-network-authority ADDRESS`
625625

@@ -672,7 +672,7 @@ EXAMPLES
672672
$ gateway-eth remove-network-authority 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123
673673
```
674674

675-
_See code: [dist/commands/remove-network-authority.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.10/dist/commands/remove-network-authority.ts)_
675+
_See code: [dist/commands/remove-network-authority.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.11/dist/commands/remove-network-authority.ts)_
676676

677677
## `gateway-eth revoke ADDRESS`
678678

@@ -725,7 +725,7 @@ EXAMPLES
725725
$ gateway-eth revoke 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123
726726
```
727727

728-
_See code: [dist/commands/revoke.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.10/dist/commands/revoke.ts)_
728+
_See code: [dist/commands/revoke.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.11/dist/commands/revoke.ts)_
729729

730730
## `gateway-eth unfreeze ADDRESS`
731731

@@ -778,7 +778,7 @@ EXAMPLES
778778
$ gateway-eth unfreeze 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123
779779
```
780780

781-
_See code: [dist/commands/unfreeze.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.10/dist/commands/unfreeze.ts)_
781+
_See code: [dist/commands/unfreeze.ts](https://github.com/identity-com/on-chain-identity-gateway/blob/v0.0.11/dist/commands/unfreeze.ts)_
782782

783783
## `gateway-eth verify ADDRESS`
784784

ethereum/gatekeeper-cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@identity.com/gateway-eth-cli",
3-
"version": "0.0.10",
3+
"version": "0.0.11",
44
"description": "Identity.com Gateway Protocol EVM CLI",
55
"author": "dankelleher @dankelleher",
66
"bin": {
@@ -25,7 +25,7 @@
2525
"@ethersproject/units": "^5.7.0",
2626
"@ethersproject/wallet": "^5.7.0",
2727
"@ethersproject/web": "^5.7.1",
28-
"@identity.com/gateway-eth-ts": "0.5.6",
28+
"@identity.com/gateway-eth-ts": "0.5.7",
2929
"@oclif/core": "^1.23.2",
3030
"@oclif/dev-cli": "^1.26.10",
3131
"@oclif/plugin-help": "^5",

ethereum/gatekeeper-cli/src/utils/oclif/gas.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {GasPriceOracle, GetTxGasParamsRes, FallbackGasPrices, GasOracleOptions} from 'gas-price-oracle'
2+
import {JsonRpcProvider, Provider} from '@ethersproject/providers'
23

34
export declare type GasPriceKey = 'instant' | 'fast' | 'standard' | 'low';
45

@@ -31,23 +32,37 @@ export const DEFAULT_GAS_PRICES: { [key: number]: FallbackGasPrices } = {
3132

3233
const options: GasOracleOptions = {
3334
chainId: 1,
34-
// defaultRpc: 'https://api.mycryptoapi.com/eth',
35+
defaultRpc: 'https://api.mycryptoapi.com/eth',
3536
timeout: 10_000,
3637
shouldCache: true,
3738
}
3839

3940
export const estimateGasPrice = async (
41+
provider: Provider,
4042
priceKey?: GasPriceKey,
4143
oracleOptions: Partial<GasOracleOptions> = {},
4244
): Promise<GetTxGasParamsRes> => {
43-
const oracle = new GasPriceOracle({
44-
fallbackGasPrices: DEFAULT_GAS_PRICES[oracleOptions.chainId || 1],
45+
const chainId = await provider.getNetwork().then(network => network.chainId)
46+
const defaultRpc = Object.hasOwn(provider, 'connection') ? (provider as JsonRpcProvider).connection.url : undefined
47+
const resolvedOptions = {
4548
...options,
49+
fallbackGasPrices: DEFAULT_GAS_PRICES[oracleOptions.chainId || 1],
50+
chainId,
51+
defaultRpc,
52+
...(priceKey ? {legacySpeed: priceKey} : {isLegacy: false}),
53+
4654
...oracleOptions,
55+
}
56+
const payload = priceKey ? {legacySpeed: priceKey} : {isLegacy: false}
57+
58+
console.log('Payload to Gas Price Oracle', {
59+
payload,
60+
resolvedOptions,
4761
})
4862

49-
const payload = priceKey ? {legacySpeed: priceKey} : {isLegacy: false}
50-
const txGasParams = await oracle.getTxGasParams(payload)
63+
const oracle = new GasPriceOracle(resolvedOptions)
64+
65+
const txGasParams = await oracle.getTxGasParams()
5166

5267
console.log('Result from Gas Price Oracle', txGasParams)
5368

ethereum/gatekeeper-cli/src/utils/oclif/utils.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ export const makeGatewayTs = async ({
1111
gasLimit,
1212
}: { provider: Provider, privateKey?: string, gatewayTokenAddress: string, fees?: GasPriceKey, gasLimit?: BigNumber }):Promise<GatewayTs> => {
1313
const signer = privateKey ? getSigner(privateKey, provider) : undefined
14-
const chainId = await provider.getNetwork().then(network => network.chainId)
15-
const feeAmount = await estimateGasPrice(fees, {
16-
chainId,
17-
})
14+
const feeAmount = await estimateGasPrice(provider, fees)
1815
return new GatewayTs(signer || provider, gatewayTokenAddress, {...feeAmount, gasLimit})
1916
}
2017

ethereum/gateway-eth-ts/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@identity.com/gateway-eth-ts",
3-
"version": "0.5.6",
3+
"version": "0.5.7",
44
"description": "Adapter library for Identity.com gateway token system on Ethereum",
55
"main": "dist/index.js",
66
"scripts": {
@@ -33,7 +33,8 @@
3333
"eth-sig-util": "2.1.1",
3434
"ethers": "^5.7.2",
3535
"gas-price-oracle": "^0.3.3",
36-
"ramda": "^0.28.0"
36+
"ramda": "^0.28.0",
37+
"tslib": "^2.5.0"
3738
},
3839
"devDependencies": {
3940
"@types/chai": "^4.3.0",
@@ -54,7 +55,6 @@
5455
"prettier": "2.3.2",
5556
"ts-mocha": "^8.0.0",
5657
"ts-node": "^10.1.0",
57-
"tslib": "^2.3.0",
5858
"typedoc": "^0.23.24",
5959
"typescript": "^4.3.5"
6060
},

ethereum/gateway-eth-ts/src/service/GatewayTs.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
TokenData,
1616
} from "../utils";
1717
import { asProvider } from "../utils/provider";
18+
import { GatewayTsTransaction } from "./GatewayTsTransaction";
1819

1920
export class GatewayTs extends GatewayTsInternal<
2021
GatewayToken,
@@ -51,6 +52,10 @@ export class GatewayTs extends GatewayTsInternal<
5152
);
5253
}
5354

55+
public transaction(): GatewayTsTransaction {
56+
return new GatewayTsTransaction(this.gatewayTokenContract, this.options);
57+
}
58+
5459
public onGatewayTokenChange(
5560
owner: string,
5661
network: bigint,
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import {
2+
BaseProvider,
3+
getDefaultProvider,
4+
TransactionReceipt,
5+
} from "@ethersproject/providers";
6+
import { TokenState } from "../utils";
7+
import * as assert from "assert";
8+
import * as dotenv from "dotenv";
9+
import { GatewayTs } from "./GatewayTs";
10+
import {
11+
deployerWallet,
12+
gatekeeperNetwork,
13+
gatekeeperWallet,
14+
TEST_GATEWAY_TOKEN_ADDRESS,
15+
} from "./testUtils";
16+
import { PopulatedTransaction } from "ethers/lib/ethers";
17+
import { GatewayTsForwarder } from "./GatewayTsForwarder";
18+
import { Wallet } from "ethers";
19+
import { BigNumber } from "ethers";
20+
21+
dotenv.config();
22+
23+
describe.only("GatewayTS Transaction", function () {
24+
let gateway: GatewayTsForwarder;
25+
let provider: BaseProvider;
26+
27+
let gatekeeper: Wallet;
28+
29+
const sampleWalletAddress = Wallet.createRandom().address;
30+
31+
before("Initialize GatewayTS class", function () {
32+
this.timeout(20_000);
33+
34+
provider = getDefaultProvider("http://localhost:8545");
35+
36+
// use the deployer account here as the relayer, as they are guaranteed to be funded by hardhat on localnet startup
37+
gatekeeper = gatekeeperWallet(provider);
38+
39+
console.log("Gatekeeper:", gatekeeper.address);
40+
41+
gateway = new GatewayTs(
42+
gatekeeper,
43+
TEST_GATEWAY_TOKEN_ADDRESS.gatewayToken
44+
).transaction();
45+
});
46+
47+
it("should issue a token", async () => {
48+
const transaction = await gateway.issue(
49+
sampleWalletAddress,
50+
gatekeeperNetwork
51+
);
52+
53+
const txReceipt = await (
54+
await gatekeeper.sendTransaction(transaction)
55+
).wait();
56+
57+
console.log("TX receipt:", txReceipt);
58+
59+
const token = await gateway.getToken(
60+
sampleWalletAddress,
61+
gatekeeperNetwork
62+
);
63+
64+
assert.equal(token.owner, sampleWalletAddress);
65+
assert.equal(token.state, TokenState.ACTIVE);
66+
});
67+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Wallet, Contract, Overrides, PopulatedTransaction } from "ethers";
2+
import { Forwarder, GatewayToken } from "../contracts/typechain-types";
3+
import { GatewayTsInternal } from "./GatewayTsInternal";
4+
import {
5+
mappedOpNames,
6+
WriteOps,
7+
ReadOnlyOperation,
8+
readOnlyOpNames,
9+
} from "../utils/types";
10+
import { mapObjIndexed, pick } from "ramda";
11+
import { signMetaTxRequest } from "../utils/metatx";
12+
import { Provider } from "@ethersproject/providers";
13+
14+
type MappedGatewayToken = ReadOnlyOperation &
15+
Pick<GatewayToken["populateTransaction"], WriteOps>;
16+
17+
// A GatewayToken API that returns an PopulatedTransaction, rather than
18+
// a transaction directly on the GatewayToken contract. Use this for relaying with relayers that provide their own
19+
// forwarder, or any other process that wants to separate tx building and signing
20+
export class GatewayTsTransaction extends GatewayTsInternal<
21+
MappedGatewayToken,
22+
PopulatedTransaction
23+
> {
24+
constructor(gatewayTokenContract: GatewayToken, options?: Overrides) {
25+
// construct a new mappedGatewayToken object comprising write operations that return PopulatedTransactions
26+
// and read operations that don't. See the description of MappedGatewayToken above for more details.
27+
const raw: ReadOnlyOperation = pick(readOnlyOpNames, gatewayTokenContract);
28+
const mapped: Pick<GatewayToken["populateTransaction"], WriteOps> = pick(
29+
mappedOpNames,
30+
gatewayTokenContract.populateTransaction
31+
);
32+
const mappedGatewayToken = {
33+
...mapped,
34+
...raw,
35+
};
36+
super(mappedGatewayToken, options);
37+
}
38+
}

ethereum/yarn.lock

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13627,11 +13627,16 @@ tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
1362713627
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
1362813628
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
1362913629

13630-
tslib@^2, tslib@^2.0.0, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.0, tslib@^2.3.1, tslib@^2.4.1:
13630+
tslib@^2, tslib@^2.0.0, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.1, tslib@^2.4.1:
1363113631
version "2.4.1"
1363213632
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.1.tgz#0d0bfbaac2880b91e22df0768e55be9753a5b17e"
1363313633
integrity sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==
1363413634

13635+
tslib@^2.5.0:
13636+
version "2.5.0"
13637+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf"
13638+
integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==
13639+
1363513640
1363613641
version "0.0.1"
1363713642
resolved "https://registry.yarnpkg.com/tsort/-/tsort-0.0.1.tgz#e2280f5e817f8bf4275657fd0f9aebd44f5a2786"

0 commit comments

Comments
 (0)