Skip to content
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(interfaces): add methods for gar to ArIO contract interface #31

Merged
merged 27 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8b81335
chore(interfaces): add methods to ArIO contract interface
Mar 26, 2024
52c4be1
chore(ario): add gar methods to client
Mar 27, 2024
dd02693
Merge branch 'PE-5753-gar-write' into PE-5753-add-gar-methods
Mar 27, 2024
e01b08b
feat(gar methods): add gar write methods to the ario client
Mar 27, 2024
f5e7774
fix(gar write): fix types and flow on gar write
Mar 27, 2024
fa6a638
fix(types): use partial write type
Mar 29, 2024
13790c6
chore(readme): update readme with new ario methods
Mar 29, 2024
9fcf440
fix(readme): update joinNetwork docs
Apr 3, 2024
68b555a
chore(connect): update connect workflow
Apr 5, 2024
beb8610
fix(mixin): filter private methods in mixin util
Apr 5, 2024
765f39c
fix(connect): add init static function on ario class to create intera…
Apr 8, 2024
8458185
fix(tests): add test cases as a const
Apr 9, 2024
c7860ed
fix(exports): add arweavesigner and arconnectsigner to exports, clean…
Apr 9, 2024
e3c97e9
fix(overloads): only accept warp contract as a contract config for ar…
Apr 9, 2024
e9985dd
fix(types): update tests, readme, and types
Apr 10, 2024
ad9bc56
fix(contract functions): correct contract function names
Apr 10, 2024
059653c
fix(tests): update client instantiation test to check read vs write c…
Apr 10, 2024
b68ad02
chore(readme): update init description
atticusofsparta Apr 10, 2024
2a0a38b
chore(readme): abreviate description of ariowritable
atticusofsparta Apr 10, 2024
f64c97f
chore(readme): comment for ariowritable describing apis
atticusofsparta Apr 10, 2024
26b9f53
chore(tests): add arIoWritable tests and testing for write functions …
Apr 10, 2024
d324158
chore(tests): add more testing coverage
Apr 11, 2024
977312a
chore(readme): update readme examples and comments
Apr 11, 2024
2cad263
Merge pull request #33 from ar-io/connect-workflow
atticusofsparta Apr 12, 2024
a43a891
Merge remote-tracking branch 'origin/alpha' into PE-5753-add-gar-methods
Apr 12, 2024
f025171
fix(logs): removing debug logs
Apr 12, 2024
857ebdc
fix(types): require atleast one param to update gateway settings
Apr 15, 2024
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
197 changes: 169 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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();
```
Expand All @@ -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>
Expand All @@ -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();
```
Expand All @@ -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();
```
Expand All @@ -173,29 +173,29 @@ The SDK provides TypeScript types. When you import the SDK in a TypeScript proje

### APIs

#### `connect(signer)`

Connects an `ArweaveSigner` or `ArConnectSigner` instance to the client for performing `writeInteraction` calls.
Supported only on clients configured with a `WarpContract` instance.
#### `init({ signer })`

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.
Factory function to that creates a read-only or writeabe client. By providing a `signer` additional write APIs that require signing, like `joinNetwork` and `delegateStake` are available. By default, a read-only client is returned and no write APIs are available.

```typescript
const arIO = new ArIO();
// read-only client that has access to all read APIs
const arIOReadable = ArIO.init()

const browserSigner = new ArConnectSigner(window.arweaveWallet);
arIO.connect(browserSigner);
const arIOWriteable = ArIO.init({ signer: browserSigner});

const nodeSigner = new ArweaveSigner(JWK);
arIO.connect(nodeSigner);
// read and write client that has access to all APIs
const arIOWriteable = ArIO.init({ signer: nodeSigner});

```

#### `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',
});
Expand All @@ -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:
Expand All @@ -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',
});
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -569,25 +569,166 @@ const auctions = await arIO.getAuctions({ evaluationOptions });
// }
```

#### `joinNetwork(params) ~ Requires signer during init()`

Joins a gateway to the ar.io network via its associated wallet.

```typescript
const jointNetworkParams = {
/* initial operator stake */
qty: 4000,
/* delegated staking settings */
allowDelegatedStaking: true,
minDelegatedStake: 100,
delegateRewardShareRatio: 1,
autoStake: true,
/* gateway metadata info */
label: 'john smith', // min 1, max 64 characters
note: 'The example gateway', // max 256 characters
properties: 'FH1aVetOoulPGqgYukj0VE0wIhDy90WiQoV3U2PeY44', // Arweave transaction ID containing additional properties of the Gateway.
/* gateway info */
fqdn: 'example.com',
port: 443,
protocol: 'https',
};
const signer = new ArweaveSigner(jwk);
// signer required for write interactions APIs
const authenticatedArIO = ArIO.init({ signer });
const joinNetworkTx = await authenticatedArIO.joinNetwork(joinNetworkParams);

// joinNetworkTx is an Arweave transaction.
// example:
// joinNetworkTx.id
// t4Xr0_J4Iurt7caNST02cMotaz2FIbWQ4Kbj616RHl3
```

#### `updateGatewaySettings(gatewaySettings) ~ Requires signer during init()`

Writes new gateway settings to the callers gateway configuration.

```typescript
const updateGatewaySettingsParams = {
minDelegatedStake: 100,
};

const signer = new ArweaveSigner(jwk);
// signer required for write interactions APIs
const authenticatedArIO = ArIO.init({ signer });
const updateGatewaySettingsTx = await authenticatedArIO.updateGatewaySettings(
updateGatewaySettingsParams,
);

// updateGatewaySettingsTx is an Arweave transaction.
// example:
// updateGatewaySettingsTx.id
// t4Xr0_J4Iurt7caNST02cMotaz2FIbWQ4Kbj616RHl3
```

#### `increaseDelegateStake({ target, qty }) ~ Requires signer during init()`

Increases the callers stake on the target gateway.

```typescript
const params = {
target: 't4Xr0_J4Iurt7caNST02cMotaz2FIbWQ4Kbj616RHl3',
qty: 100,
};

const signer = new ArweaveSigner(jwk);
// signer required for write interactions APIs
const authenticatedArIO = ArIO.init({ signer });
const increaseDelegateStakeTx =
await authenticatedArIO.increaseDelegateStake(params);

// increaseDelegateStakeTx is an Arweave transaction.
// example:
// increaseDelegateStakeTx.id
// fDrr0_J4Iurt7caNST02cMotaz2FIbWQ4Kcj616RHl3
```

#### `decreaseDelegateStake({ target, qty }) ~ Requires signer during init()`

Decreases the callers stake on the target gateway.

```typescript
const params = {
target: 't4Xr0_J4Iurt7caNST02cMotaz2FIbWQ4Kbj616RHl3',
qty: 100,
};

const signer = new ArweaveSigner(jwk);
// signer required for write interactions APIs
const authenticatedArIO = ArIO.init({ signer });
const decreaseDelegateStakeTx =
await authenticatedArIO.decreaseDelegateStake(params);

// decreaseDelegateStakeTx is an Arweave transaction.
// example:
// decreaseDelegateStakeTx.id
// fDrr0_J4Iurt7caNST02cMotaz2FIbWQ4Kcj616RHl3
```

#### `increaseOperatorStake({ qty }) ~ Requires signer during init()`

Increases the callers operator stake. Must be executed with a wallet registered as a gateway operator.

```typescript
const params = {
qty: 100,
};

const signer = new ArweaveSigner(jwk);
// signer required for write interactions APIs
const authenticatedArIO = ArIO.init({ signer });
const increaseOperatorStakeTx =
await authenticatedArIO.increaseOperatorStake(params);

// increaseOperatorStakeTx is an Arweave transaction.
// example:
// increaseOperatorStakeTx.id
// fDrr0_J4Iurt7caNST02cMotaz2FIbWQ4Kcj616RHl3
```

#### `decreaseOperatorStake({ qty }) ~ Requires signer during init()`

Decreases the callers operator stake. Must be executed with a wallet registered as a gateway operator.

```typescript
const params = {
qty: 100,
};

const signer = new ArweaveSigner(jwk);
// signer required for write interactions APIs
const authenticatedArIO = ArIO.init({ signer });
const decreaseOperatorStakeTx =
await authenticatedArIO.decreaseOperatorStake(params);

// decreaseOperatorStakeTx is an Arweave transaction.
// example:
// decreaseOperatorStakeTx.id
// fDrr0_J4Iurt7caNST02cMotaz2FIbWQ4Kcj616RHl3
```

### Custom Contracts

The ArIO contract client class exposes APIs relevant to the ar.io contract. It can be configured to use any contract ID that adheres to the spec of the ar.io contract. In the default case, it will automatically build and utilize a contract data provider interface that is configured to point the the known mainnet contract ID at construction time. You can provide custom contract data provider or, alternatively, a `contractTxId` to the ArIO constructor to use a different, ar.io-spec-compatible contract.

```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',
}),
Expand Down
2 changes: 1 addition & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
moduleFileExtensions: ['ts', 'js', 'mjs'],
testMatch: ['**/src/**/*.test.ts'],
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts', 'tests/**/*.ts'],
collectCoverageFrom: ['src/**/*.ts'],
testEnvironment: 'node',
testTimeout: 120_000,
extensionsToTreatAsEsm: ['.ts'],
Expand Down
2 changes: 1 addition & 1 deletion jest.integration.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
moduleFileExtensions: ['ts', 'js', 'mjs'],
testMatch: ['**/tests/**/*.test.ts'],
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts', 'tests/**/*.ts'],
collectCoverageFrom: ['src/**/*.ts'],
testEnvironment: 'node',
testTimeout: 120_000,
extensionsToTreatAsEsm: ['.ts'],
Expand Down
Loading