Skip to content

Commit

Permalink
Merge pull request #188 from ar-io/alpha
Browse files Browse the repository at this point in the history
chore: release v2.2.0
  • Loading branch information
dtfiedler authored Aug 30, 2024
2 parents 18e8f81 + 6d72c57 commit 94fc9d0
Show file tree
Hide file tree
Showing 18 changed files with 301 additions and 236 deletions.
6 changes: 3 additions & 3 deletions examples/cjs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,9 @@ axios@1.7.2:
proxy-from-env "^1.1.0"

axios@^1.4.0:
version "1.6.8"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66"
integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==
version "1.7.3"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.3.tgz#a1125f2faf702bc8e8f2104ec3a76fab40257d85"
integrity sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
Expand Down
6 changes: 3 additions & 3 deletions examples/esm/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,9 @@ axios@1.7.2:
proxy-from-env "^1.1.0"

axios@^1.4.0:
version "1.6.8"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66"
integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==
version "1.7.3"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.3.tgz#a1125f2faf702bc8e8f2104ec3a76fab40257d85"
integrity sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
Expand Down
24 changes: 12 additions & 12 deletions examples/vite/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1461,11 +1461,11 @@ brace-expansion@^2.0.1:
balanced-match "^1.0.0"

braces@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==
version "3.0.3"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789"
integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==
dependencies:
fill-range "^7.0.1"
fill-range "^7.1.1"

brorand@^1.0.1, brorand@^1.1.0:
version "1.1.0"
Expand Down Expand Up @@ -2298,10 +2298,10 @@ filelist@^1.0.4:
dependencies:
minimatch "^5.0.1"

fill-range@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==
fill-range@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292"
integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==
dependencies:
to-regex-range "^5.0.1"

Expand Down Expand Up @@ -4525,10 +4525,10 @@ tweetnacl@^1.0.3:
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596"
integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==

typescript@^4.9.5:
version "4.9.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==
typescript@^5.3.3:
version "5.5.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba"
integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==

undici-types@~5.26.4:
version "5.26.5"
Expand Down
22 changes: 11 additions & 11 deletions examples/webpack/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2345,9 +2345,9 @@ axios@1.7.2:
proxy-from-env "^1.1.0"

axios@^1.4.0:
version "1.6.8"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66"
integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==
version "1.7.3"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.3.tgz#a1125f2faf702bc8e8f2104ec3a76fab40257d85"
integrity sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
Expand Down Expand Up @@ -2515,11 +2515,11 @@ brace-expansion@^2.0.1:
balanced-match "^1.0.0"

braces@^3.0.2, braces@~3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==
version "3.0.3"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789"
integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==
dependencies:
fill-range "^7.0.1"
fill-range "^7.1.1"

brorand@^1.0.1, brorand@^1.1.0:
version "1.1.0"
Expand Down Expand Up @@ -3688,10 +3688,10 @@ file-loader@^6.2.0:
loader-utils "^2.0.0"
schema-utils "^3.0.0"

fill-range@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==
fill-range@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292"
integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==
dependencies:
to-regex-range "^5.0.1"

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ar.io/sdk",
"version": "2.1.0",
"version": "2.2.0-alpha.4",
"repository": {
"type": "git",
"url": "git+https://github.com/ar-io/ar-io-sdk.git"
Expand Down Expand Up @@ -123,11 +123,12 @@
"@permaweb/aoconnect": "^0.0.57",
"arbundles": "0.11.0",
"arweave": "1.14.4",
"axios": "1.7.2",
"axios": "1.7.3",
"axios-retry": "^4.3.0",
"eventemitter3": "^5.0.1",
"plimit-lit": "^3.0.1",
"winston": "^3.13.0"
"winston": "^3.13.0",
"zod": "^3.23.8"
},
"lint-staged": {
"**/*.{ts,js,mjs,cjs,md,json}": [
Expand Down
4 changes: 3 additions & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
} from '@permaweb/aoconnect';
import { Signer } from 'arbundles';

import { AoSigner } from './token.js';

export type BlockHeight = number;
export type SortKey = string;
export type Timestamp = number;
Expand All @@ -33,7 +35,7 @@ export type TransactionId = string;
export type ProcessId = string;

// TODO: append this with other configuration options (e.g. local vs. remote evaluation)
export type ContractSigner = Signer | Window['arweaveWallet'];
export type ContractSigner = Signer | Window['arweaveWallet'] | AoSigner;
export type WithSigner<T = NonNullable<unknown>> = {
signer: ContractSigner;
} & T; // TODO: optionally allow JWK in place of signer
Expand Down
2 changes: 1 addition & 1 deletion src/common/ant-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ANTRegistry {
static init({
signer,
...config
}: WithSigner<Required<ProcessConfiguration>>): AoANTRegistryRead;
}: WithSigner<Required<ProcessConfiguration>>): AoANTRegistryWrite;
static init(
config?: OptionalSigner<ProcessConfiguration>,
): AoANTRegistryRead | AoANTRegistryWrite {
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ export const IO_TESTNET_PROCESS_ID =
export const ANT_REGISTRY_ID = 'i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc';
export const MIO_PER_IO = 1_000_000;
export const AOS_MODULE_ID = 'cbn0KKrBZH7hdNkNokuXLtGryrWM--PjSTBqIzw9Kkk';
export const ANT_LUA_ID = 'Flwio4Lr08g6s6uim6lEJNnVGD9ylvz0_aafvpiL8FI';
export const ANT_LUA_ID = 'BVZZ0_ME8uq3zChN6bA6WsPmFhVpGDJ7Rb7l4qoGIDM';
export const DEFAULT_SCHEDULER_ID =
'_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';
21 changes: 18 additions & 3 deletions src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,26 @@ export type AoVaultData = {
endTimestamp: Timestamp;
};

export type AoEpochDistributionRewards = {
eligible: Record<
WalletAddress,
{
delegateRewards: Record<WalletAddress, number>;
operatorReward: number;
}
>;
// TODO: we could create a new type for this
distributed?: Record<WalletAddress, number>;
};

export type AoEpochDistributionData = {
rewards: Record<WalletAddress, number>;
distributedTimestamp: Timestamp;
totalDistributedRewards: number;
rewards: AoEpochDistributionRewards;
totalEligibleRewards: number;
totalEligibleObserverReward: number;
totalEligibleGatewayReward: number;
// TODO: we could create a new type for this
distributedTimestamp?: Timestamp; // only set if rewards have been distributed
totalDistributedRewards?: number; // only set if rewards have been distributed
};

export type AoArNSReservedNameData = {
Expand Down
88 changes: 87 additions & 1 deletion src/utils/ao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
*/
import { connect, createDataItemSigner } from '@permaweb/aoconnect';
import { createData } from 'arbundles';
import { z } from 'zod';

import { defaultArweave } from '../common/arweave.js';
import { AOProcess } from '../common/index.js';
import { ANTRegistry, AOProcess, Logger } from '../common/index.js';
import {
ANT_LUA_ID,
ANT_REGISTRY_ID,
Expand All @@ -27,6 +28,7 @@ import {
} from '../constants.js';
import {
AoANTRecord,
AoANTState,
AoClient,
AoSigner,
ContractSigner,
Expand Down Expand Up @@ -59,6 +61,13 @@ export async function spawnANT({
stateContractTxId?: string;
antRegistryId?: string;
}): Promise<string> {
const registryClient = ANTRegistry.init({
process: new AOProcess({
processId: antRegistryId,
ao,
}),
signer: signer,
});
//TODO: cache locally and only fetch if not cached
const luaString = (await defaultArweave.transactions.getData(luaCodeTxId, {
decode: true,
Expand Down Expand Up @@ -105,6 +114,8 @@ export async function spawnANT({
});
}

await registryClient.register({ processId });

return processId;
}

Expand Down Expand Up @@ -143,7 +154,43 @@ export async function evolveANT({
return id;
}

export function isAoSigner(value: unknown): value is AoSigner {
const TagSchema = z.object({
name: z.string(),
value: z.union([z.string(), z.number()]),
});

const AoSignerSchema = z
.function()
.args(
z.object({
data: z.union([z.string(), z.instanceof(Buffer)]),
tags: z.array(TagSchema).optional(),
target: z.string().optional(),
anchor: z.string().optional(),
}),
)
.returns(
z.promise(
z.object({
id: z.string(),
raw: z.instanceof(ArrayBuffer),
}),
),
);
try {
AoSignerSchema.parse(value);
return true;
} catch {
return false;
}
}

export function createAoSigner(signer: ContractSigner): AoSigner {
if (isAoSigner(signer)) {
return signer;
}

if (!('publicKey' in signer)) {
return createDataItemSigner(signer) as AoSigner;
}
Expand All @@ -167,3 +214,42 @@ export function createAoSigner(signer: ContractSigner): AoSigner {

return aoSigner;
}

// using passThrough to require the minimum fields and allow others (eg TotalSupply, Logo, etc)
export const AntStateSchema = z
.object({
Name: z.string(),
Ticker: z.string(),
Owner: z.string(),
Controllers: z.array(z.string()),
Records: z.record(
z.string(),
z
.object({
transactionId: z.string(),
ttlSeconds: z.number(),
})
.passthrough(),
),
Balances: z.record(z.string(), z.number()),
})
.passthrough();

/**
* @param state
* @returns {boolean}
* @throws {z.ZodError} if the state object does not match the expected schema
*/
export function isAoANTState(
state: object,
logger: Logger = Logger.default,
): state is AoANTState {
try {
AntStateSchema.parse(state);
return true;
} catch (error) {
// this allows us to see the path of the error in the object as well as the expected schema on invalid fields
logger.error(error.issues);
return false;
}
}
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

// AUTOMATICALLY GENERATED FILE - DO NOT TOUCH

export const version = '2.1.0';
export const version = '2.2.0-alpha.4';
Loading

0 comments on commit 94fc9d0

Please sign in to comment.