-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(init): Remove connect workflow and create factory init method #33
Changes from 6 commits
68b555a
beb8610
765f39c
8458185
c7860ed
e3c97e9
e9985dd
ad9bc56
059653c
b68ad02
2a0a38b
f64c97f
26b9f53
d324158
977312a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -13,7 +13,7 @@ This is the home of [ar.io] SDK. This SDK provides functionality for interacting | |||||||
- [Typescript](#typescript) | ||||||||
- [ArIO Contract](#ario-contract) | ||||||||
- [APIs](#apis) | ||||||||
- [connect](#connectsigner) | ||||||||
- [init](#init-signer) | ||||||||
- [getBalance](#getbalance-address-evaluationoptions-) | ||||||||
- [getBalances](#getbalances-evaluationoptions-) | ||||||||
- [getGateway](#getgateway-address-evaluationoptions-) | ||||||||
|
@@ -66,7 +66,7 @@ yarn add @ar-io/sdk | |||||||
```typescript | ||||||||
import { ArIO } from '@ar-io/sdk'; | ||||||||
|
||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
const gateways = arIO.getGateways(); | ||||||||
|
||||||||
// outputs: | ||||||||
|
@@ -123,7 +123,7 @@ The SDK is provided in both CommonJS and ESM formats and is compatible with bund | |||||||
import { ArIO } from '@ar-io/sdk'; | ||||||||
|
||||||||
// set up client | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
// fetch gateways | ||||||||
const gateways = arIO.getGateways(); | ||||||||
``` | ||||||||
|
@@ -135,7 +135,7 @@ const gateways = arIO.getGateways(); | |||||||
import { ArIO } from 'https://unpkg.com/@ar-io/sdk'; | ||||||||
|
||||||||
// set up client | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
// fetch gateways | ||||||||
const gateways = await arIO.getGateways(); | ||||||||
</script> | ||||||||
|
@@ -149,7 +149,7 @@ const gateways = arIO.getGateways(); | |||||||
import { ArIO } from '@ar-io/sdk/node'; | ||||||||
|
||||||||
// set up client | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
// fetch gateways | ||||||||
const gateways = await arIO.getGateways(); | ||||||||
``` | ||||||||
|
@@ -160,7 +160,7 @@ const gateways = await arIO.getGateways(); | |||||||
import { ArIO } from '@ar-io/sdk'; | ||||||||
|
||||||||
// set up client | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
// fetch gateways | ||||||||
const gateways = await arIO.getGateways(); | ||||||||
``` | ||||||||
|
@@ -173,29 +173,29 @@ The SDK provides TypeScript types. When you import the SDK in a TypeScript proje | |||||||
|
||||||||
### APIs | ||||||||
|
||||||||
#### `connect(signer)` | ||||||||
#### `init({ signer })` | ||||||||
|
||||||||
Connects an `ArweaveSigner` or `ArConnectSigner` instance to the client for performing `writeInteraction` calls. | ||||||||
Supported only on clients configured with a `WarpContract` instance. | ||||||||
If a signer is passed in, connects an `ArweaveSigner` or `ArConnectSigner` instance to the client for performing `writeInteraction` calls. | ||||||||
If `signer` is passed in, returns an `ArIOWritable` instance. Otherwise will return a `ArIOReadable`. | ||||||||
atticusofsparta marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
||||||||
NOTE: if you have a client configured with a `RemoteContract` instance, it will be overriden with a `WarpContract` instance using the existing configuration of the `RemoteContract` instance when `connect` is executed. | ||||||||
The `ArIOWritable` has access to read methods as well as write methods. | ||||||||
atticusofsparta marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
||||||||
```typescript | ||||||||
const arIO = new ArIO(); | ||||||||
dtfiedler marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
||||||||
const browserSigner = new ArConnectSigner(window.arweaveWallet); | ||||||||
arIO.connect(browserSigner); | ||||||||
const arIOWriteable = ArIO.init({ signer: browserSigner}); | ||||||||
|
||||||||
const nodeSigner = new ArweaveSigner(JWK); | ||||||||
arIO.connect(nodeSigner); | ||||||||
const arIOWriteable = ArIO.init({ signer: nodeSigner}); | ||||||||
atticusofsparta marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
||||||||
const arIOReadable = ArIO.init() | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this up top and add a comment
Suggested change
|
||||||||
``` | ||||||||
|
||||||||
#### `getBalance({ address, evaluationOptions })` | ||||||||
|
||||||||
Retrieves the balance of the specified wallet address. | ||||||||
|
||||||||
```typescript | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
const balance = arIO.getBalance({ | ||||||||
address: 'INSERT_WALLET_ADDRESS', | ||||||||
}); | ||||||||
|
@@ -214,7 +214,7 @@ Retrieves the balances of the ArIO contract. | |||||||
--> | ||||||||
|
||||||||
```typescript | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
const balances = arIO.getBalances(); | ||||||||
|
||||||||
// outputs: | ||||||||
|
@@ -232,7 +232,7 @@ const balances = arIO.getBalances(); | |||||||
Retrieves a gateway's info by its staking wallet address. | ||||||||
|
||||||||
```typescript | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
const gateway = arIO.getGateway({ | ||||||||
address: 'INSERT_GATEWAY_ADDRESS', | ||||||||
}); | ||||||||
|
@@ -277,7 +277,7 @@ const gateway = arIO.getGateway({ | |||||||
Retrieves the registered gateways of the ArIO contract. | ||||||||
|
||||||||
```typescript | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
const gateways = arIO.getGateways(); | ||||||||
|
||||||||
// outputs: | ||||||||
|
@@ -327,7 +327,7 @@ const gateways = arIO.getGateways(); | |||||||
Retrieves the record info of the specified ArNS name. | ||||||||
|
||||||||
```typescript | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
const record = arIO.getArNSRecord({ domain: 'ardrive' }); | ||||||||
|
||||||||
// outputs | ||||||||
|
@@ -346,7 +346,7 @@ const record = arIO.getArNSRecord({ domain: 'ardrive' }); | |||||||
Retrieves all registered ArNS records of the ArIO contract. | ||||||||
|
||||||||
```typescript | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
const records = arIO.getArNSRecords(); | ||||||||
|
||||||||
// outputs: | ||||||||
|
@@ -375,7 +375,7 @@ const records = arIO.getArNSRecords(); | |||||||
Returns the epoch-indexed observation list. | ||||||||
|
||||||||
```typescript | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
const observations = await arIO.getObservations(); | ||||||||
|
||||||||
// output | ||||||||
|
@@ -399,7 +399,7 @@ const observations = await arIO.getObservations(); | |||||||
Returns the current rewards distribution information. The resulting object is pruned, to get older distributions use the `evaluationOptions` to `evalTo` a previous state. | ||||||||
|
||||||||
```typescript | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
const distributions = await arIO.getDistributions(); | ||||||||
|
||||||||
// output | ||||||||
|
@@ -418,7 +418,7 @@ const distributions = await arIO.getDistributions(); | |||||||
Returns the epoch data for the specified block height. | ||||||||
|
||||||||
```typescript | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
const epoch = await arIO.getEpoch({ blockHeight: 1382230 }); | ||||||||
|
||||||||
// output | ||||||||
|
@@ -438,7 +438,7 @@ const epoch = await arIO.getEpoch({ blockHeight: 1382230 }); | |||||||
Returns the current epoch data. | ||||||||
|
||||||||
```typescript | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
const epoch = await arIO.getCurrentEpoch(); | ||||||||
|
||||||||
// output | ||||||||
|
@@ -458,7 +458,7 @@ const epoch = await arIO.getCurrentEpoch(); | |||||||
Retrieves the prescribed observers of the ArIO contract. To fetch prescribed observers for a previous epoch set the `evaluationOptions` to the desired epoch. | ||||||||
|
||||||||
```typescript | ||||||||
const arIO = new ArIO(); | ||||||||
const arIO = ArIO.init(); | ||||||||
const observers = arIO.getPrescribedObservers(); | ||||||||
|
||||||||
// outputs: | ||||||||
|
@@ -569,7 +569,7 @@ const auctions = await arIO.getAuctions({ evaluationOptions }); | |||||||
// } | ||||||||
``` | ||||||||
|
||||||||
#### `joinNetwork({ ...JoinNetworkParams})` | ||||||||
#### `joinNetwork(params)` | ||||||||
|
||||||||
Joins a gateway to the ar.io network via its associated wallet. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add that this requires |
||||||||
|
||||||||
|
@@ -592,8 +592,8 @@ const jointNetworkParams = { | |||||||
protocol: 'https', | ||||||||
}; | ||||||||
const signer = new ArweaveSigner(jwk); | ||||||||
// connection required for write interactions | ||||||||
const authenticatedArIO = arIO.connect(signer); | ||||||||
// signer required for write interactions APIs | ||||||||
const authenticatedArIO = ArIO.init({ signer }); | ||||||||
dtfiedler marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
const joinNetworkTx = await authenticatedArIO.joinNetwork(joinNetworkParams); | ||||||||
|
||||||||
// joinNetworkTx is an Arweave transaction. | ||||||||
|
@@ -602,20 +602,21 @@ const joinNetworkTx = await authenticatedArIO.joinNetwork(joinNetworkParams); | |||||||
// t4Xr0_J4Iurt7caNST02cMotaz2FIbWQ4Kbj616RHl3 | ||||||||
``` | ||||||||
|
||||||||
#### `updateGatewaySettings({ ...UpdateGatewaySettingsParams})` | ||||||||
#### `updateGatewaySettings(gatewaySettings)` | ||||||||
|
||||||||
Writes new gateway settings to the callers gateway configuration. | ||||||||
|
||||||||
```typescript | ||||||||
const params = { | ||||||||
const updateGatewaySettingsParams = { | ||||||||
minDelegatedStake: 100, | ||||||||
}; | ||||||||
|
||||||||
const signer = new ArweaveSigner(jwk); | ||||||||
// connection required for write interactions | ||||||||
const authenticatedArIO = arIO.connect(signer); | ||||||||
const updateGatewaySettingsTx = | ||||||||
await authenticatedArIO.updateGatewaySettings(params); | ||||||||
const authenticatedArIO = ArIO.init({ signer }); | ||||||||
const updateGatewaySettingsTx = await authenticatedArIO.updateGatewaySettings( | ||||||||
updateGatewaySettingsParams, | ||||||||
); | ||||||||
|
||||||||
// updateGatewaySettingsTx is an Arweave transaction. | ||||||||
// example: | ||||||||
|
@@ -635,7 +636,7 @@ const params = { | |||||||
|
||||||||
const signer = new ArweaveSigner(jwk); | ||||||||
// connection required for write interactions | ||||||||
const authenticatedArIO = arIO.connect(signer); | ||||||||
const authenticatedArIO = ArIO.init({ signer }); | ||||||||
dtfiedler marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
const increaseDelegateStakeTx = | ||||||||
await authenticatedArIO.increaseDelegateStake(params); | ||||||||
|
||||||||
|
@@ -657,7 +658,7 @@ const params = { | |||||||
|
||||||||
const signer = new ArweaveSigner(jwk); | ||||||||
// connection required for write interactions | ||||||||
const authenticatedArIO = arIO.connect(signer); | ||||||||
const authenticatedArIO = ArIO.init({ signer }); | ||||||||
const decreaseDelegateStakeTx = | ||||||||
await authenticatedArIO.decreaseDelegateStake(params); | ||||||||
|
||||||||
|
@@ -678,7 +679,7 @@ const params = { | |||||||
|
||||||||
const signer = new ArweaveSigner(jwk); | ||||||||
// connection required for write interactions | ||||||||
const authenticatedArIO = arIO.connect(signer); | ||||||||
const authenticatedArIO = ArIO.init({ signer }); | ||||||||
const increaseOperatorStakeTx = | ||||||||
await authenticatedArIO.increaseOperatorStake(params); | ||||||||
|
||||||||
|
@@ -699,7 +700,7 @@ const params = { | |||||||
|
||||||||
const signer = new ArweaveSigner(jwk); | ||||||||
// connection required for write interactions | ||||||||
const authenticatedArIO = arIO.connect(signer); | ||||||||
const authenticatedArIO = ArIO.init({ signer }); | ||||||||
const decreaseOperatorStakeTx = | ||||||||
await authenticatedArIO.decreaseOperatorStake(params); | ||||||||
|
||||||||
|
@@ -715,19 +716,19 @@ The ArIO contract client class exposes APIs relevant to the ar.io contract. It c | |||||||
|
||||||||
```typescript | ||||||||
// provide a custom contractTxId to the client and default to remote evaluation | ||||||||
const remoteCustomArIO = new ArIO({ | ||||||||
const remoteCustomArIO = ArIO.init({ | ||||||||
contractTxId: 'TESTNET_CONTRACT_TX_ID', | ||||||||
}); | ||||||||
|
||||||||
// provide a custom contract to the client, and specify local evaluation using warp | ||||||||
const localCustomArIO = new ArIO({ | ||||||||
const localCustomArIO = ArIO.init({ | ||||||||
contract: new WarpContract<ArIOState>({ | ||||||||
contractTxId: 'TESTNET_CONTRACT_TX_ID', | ||||||||
}), | ||||||||
}); | ||||||||
|
||||||||
// provide a custom contract to the client, and specify local evaluation using remote cache | ||||||||
const remoteCacheCustomArIO = new ArIO({ | ||||||||
const remoteCacheCustomArIO = ArIO.init({ | ||||||||
contract: new RemoteContract<ArIOState>({ | ||||||||
contractTxId: 'TESTNET_CONTRACT_TX_ID', | ||||||||
}), | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import { ArconnectSigner, ArweaveSigner } from 'arbundles'; | |
import { DataItem } from 'warp-arbundles'; | ||
import { InteractionResult, Transaction } from 'warp-contracts'; | ||
|
||
import { RemoteContract, WarpContract } from './common/index.js'; | ||
import { | ||
ANTRecord, | ||
ANTState, | ||
|
@@ -38,25 +39,19 @@ export type WalletAddress = string; | |
|
||
// TODO: append this with other configuration options (e.g. local vs. remote evaluation) | ||
export type ContractSigner = ArweaveSigner | ArconnectSigner; | ||
export type ContractConfiguration = { | ||
signer?: ContractSigner; // TODO: optionally allow JWK in place of signer | ||
} & ( | ||
export type WithSigner = { signer: ContractSigner }; // TODO: optionally allow JWK in place of signer | ||
export type ContractConfiguration = | ||
| { | ||
contract?: | ||
| (BaseContract<unknown> & ReadContract) | ||
| (BaseContract<unknown> & ReadWriteContract); | ||
contract?: WarpContract<unknown> | RemoteContract<unknown>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this need to be optional anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think it actually ever needed to be, since we default it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we need an instance where we want to make one nullable, it can be piped thru an Omit type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually it does need to be optional for a few reasons, mainly to help enable DX, however it may be prudent to create different types rather than forcing use of this one. We should talk on it, i left as is since it was simpler that way for now. |
||
} | ||
| { | ||
contractTxId: string; | ||
} | ||
); | ||
}; | ||
|
||
export function isContractConfiguration<T>( | ||
config: ContractConfiguration, | ||
): config is { | ||
contract: | ||
| (BaseContract<T> & ReadContract) | ||
| (BaseContract<T> & ReadWriteContract); | ||
contract: WarpContract<T> | RemoteContract<T>; | ||
} { | ||
return 'contract' in config; | ||
} | ||
|
@@ -86,8 +81,6 @@ export type WriteParameters<Input> = { | |
|
||
export interface BaseContract<T> { | ||
getState(params: EvaluationParameters): Promise<T>; | ||
connect(signer: ContractSigner): this; | ||
connected(): boolean; | ||
} | ||
|
||
export interface ReadContract { | ||
|
@@ -123,7 +116,7 @@ export interface SmartWeaveContract<T> { | |
} | ||
|
||
// TODO: extend with additional methods | ||
export interface ArIOContract extends BaseContract<ArIOState> { | ||
export interface ArIOReadContract extends BaseContract<ArIOState> { | ||
getGateway({ | ||
address, | ||
evaluationOptions, | ||
|
@@ -185,6 +178,9 @@ export interface ArIOContract extends BaseContract<ArIOState> { | |
domain: string; | ||
type?: RegistrationType; | ||
}>): Promise<ArNSAuctionData>; | ||
} | ||
|
||
export interface ArIOWriteContract { | ||
// write interactions | ||
joinNetwork({ | ||
qty, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the comment below - mention that signer is optional. and if provided
ArIOWriteable
class is returned that supports write interaction APIs; otherwise anArIOReadable
class is returned and supports read apis only.