From 55f69c2f697413e1d8ea7e7b1f895ec7ad420489 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Mon, 3 Jun 2024 18:49:52 -0600 Subject: [PATCH 1/4] chore(tools): use arweave.net and update ar.io/sdk --- package.json | 2 +- tools/utilities.ts | 2 +- yarn.lock | 42 ++++++++++++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 7607d754..364eee80 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "transfer-tokens": "yarn ts-node ./tools/cli/transfer.ts" }, "devDependencies": { - "@ar.io/sdk": "1.0.7", + "@ar.io/sdk": "^1.1.0", "@commitlint/config-conventional": "^17.7.0", "@trivago/prettier-plugin-sort-imports": "^4.0.0", "@types/jest": "^27.4.0", diff --git a/tools/utilities.ts b/tools/utilities.ts index 8d6e1d35..9f86260f 100644 --- a/tools/utilities.ts +++ b/tools/utilities.ts @@ -62,7 +62,7 @@ export const networkContract = (signer: ArweaveSigner) => }); export const arweave = new Arweave({ - host: 'ar-io.dev', + host: 'arweave.net', port: 443, protocol: 'https', }); diff --git a/yarn.lock b/yarn.lock index 0a362af9..5e13daad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -183,7 +183,7 @@ __metadata: version: 0.0.0-use.local resolution: "@ar-io/arns-pilot@workspace:." dependencies: - "@ar.io/sdk": 1.0.7 + "@ar.io/sdk": ^1.1.0 "@commitlint/config-conventional": ^17.7.0 "@trivago/prettier-plugin-sort-imports": ^4.0.0 "@types/jest": ^27.4.0 @@ -216,17 +216,17 @@ __metadata: languageName: unknown linkType: soft -"@ar.io/sdk@npm:1.0.7": - version: 1.0.7 - resolution: "@ar.io/sdk@npm:1.0.7" +"@ar.io/sdk@npm:^1.1.0": + version: 1.1.0 + resolution: "@ar.io/sdk@npm:1.1.0" dependencies: arbundles: 0.11.0 - arweave: 1.15.1 - axios: 1.4.0 + arweave: 1.14.4 + axios: 1.6.0 + axios-retry: ^4.3.0 bunyan: ^1.8.15 - warp-arbundles: ^1.0.4 warp-contracts: 1.4.45 - checksum: 6beb41b4ed336a65ea9bcee0b15466cf33dad7aa39583cbb2571526427edeb981bdea98bc2ea9c643a715056062da51f9fb1c19f869614b834b1aed8cde195e5 + checksum: b1afd7190af423544148f3ee3a8eb85c40d3a83c7dec21d5eee15e1a01863f0bb48c69ee4cd56bf87ae2e8c1326bdae2fc808624b87b80a178cca1c967fb01a2 languageName: node linkType: hard @@ -3541,14 +3541,25 @@ __metadata: languageName: node linkType: hard -"axios@npm:1.4.0": - version: 1.4.0 - resolution: "axios@npm:1.4.0" +"axios-retry@npm:^4.3.0": + version: 4.3.0 + resolution: "axios-retry@npm:4.3.0" + dependencies: + is-retry-allowed: ^2.2.0 + peerDependencies: + axios: 0.x || 1.x + checksum: 7007b71c257bde2a3e63f41e9a5ef6a2a1bd2277b7cb1ee74bf5f2fa1c6f9cd99af75d739538977e5b0bec94cb27c4883c2e5fd5b919de75bb8ba571f42b5e77 + languageName: node + linkType: hard + +"axios@npm:1.6.0": + version: 1.6.0 + resolution: "axios@npm:1.6.0" dependencies: follow-redirects: ^1.15.0 form-data: ^4.0.0 proxy-from-env: ^1.1.0 - checksum: 7fb6a4313bae7f45e89d62c70a800913c303df653f19eafec88e56cea2e3821066b8409bc68be1930ecca80e861c52aa787659df0ffec6ad4d451c7816b9386b + checksum: c7c9f2ae9e0b9bad7d6f9a4dff030930b12ee667dedf54c3c776714f91681feb743c509ac0796ae5c01e12c4ab4a2bee74905068dd200fbc1ab86f9814578fb0 languageName: node linkType: hard @@ -6989,6 +7000,13 @@ __metadata: languageName: node linkType: hard +"is-retry-allowed@npm:^2.2.0": + version: 2.2.0 + resolution: "is-retry-allowed@npm:2.2.0" + checksum: 3d1103a9290b5d03626756a41054844633eac78bc5d3e3a95b13afeae94fa3cfbcf7f0b5520d83f75f48a25ce7b142fdbac4217dc4b0630f3ea55e866ec3a029 + languageName: node + linkType: hard + "is-stream@npm:^2.0.0": version: 2.0.1 resolution: "is-stream@npm:2.0.1" From 90c7367809737d1da253a1e6a3c561de93fef700 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Mon, 17 Jun 2024 08:00:57 -0700 Subject: [PATCH 2/4] chore: add ts-ignore for not all code paths return value warning --- src/contract.ts | 152 ++++++++++++++++++++++++++---------------------- 1 file changed, 82 insertions(+), 70 deletions(-) diff --git a/src/contract.ts b/src/contract.ts index d566f191..0e6db0c3 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -6,27 +6,27 @@ import { getGateway, getGateways } from './actions/read/gateways'; import { getEpoch, getPrescribedObservers } from './actions/read/observers'; import { getPriceForInteraction } from './actions/read/price'; import { getRecord } from './actions/read/record'; -import { buyRecord } from './actions/write/buyRecord'; -import { createReservedName } from './actions/write/createReservedName'; -import { createVault } from './actions/write/createVault'; -import { decreaseDelegateStake } from './actions/write/decreaseDelegateStake'; -import { decreaseOperatorStake } from './actions/write/decreaseOperatorStake'; -import { delegateStake } from './actions/write/delegateStake'; +// import { buyRecord } from './actions/write/buyRecord'; +// import { createReservedName } from './actions/write/createReservedName'; +// import { createVault } from './actions/write/createVault'; +// import { decreaseDelegateStake } from './actions/write/decreaseDelegateStake'; +// import { decreaseOperatorStake } from './actions/write/decreaseOperatorStake'; +// import { delegateStake } from './actions/write/delegateStake'; import { evolve } from './actions/write/evolve'; import { evolveState } from './actions/write/evolveState'; -import { extendRecord } from './actions/write/extendRecord'; -import { extendVault } from './actions/write/extendVault'; -import { increaseOperatorStake } from './actions/write/increaseOperatorStake'; -import { increaseUndernameCount } from './actions/write/increaseUndernameCount'; -import { increaseVault } from './actions/write/increaseVault'; -import { joinNetwork } from './actions/write/joinNetwork'; -import { leaveNetwork } from './actions/write/leaveNetwork'; -import { saveObservations } from './actions/write/saveObservations'; -import { submitAuctionBid } from './actions/write/submitAuctionBid'; +// import { extendRecord } from './actions/write/extendRecord'; +// import { extendVault } from './actions/write/extendVault'; +// import { increaseOperatorStake } from './actions/write/increaseOperatorStake'; +// import { increaseUndernameCount } from './actions/write/increaseUndernameCount'; +// import { increaseVault } from './actions/write/increaseVault'; +// import { joinNetwork } from './actions/write/joinNetwork'; +// import { leaveNetwork } from './actions/write/leaveNetwork'; +// import { saveObservations } from './actions/write/saveObservations'; +// import { submitAuctionBid } from './actions/write/submitAuctionBid'; import { tick } from './actions/write/tick'; -import { transferTokens } from './actions/write/transferTokens'; -import { updateGatewaySettings } from './actions/write/updateGatewaySettings'; -import { vaultedTransfer } from './actions/write/vaultedTransfer'; +// import { transferTokens } from './actions/write/transferTokens'; +// import { updateGatewaySettings } from './actions/write/updateGatewaySettings'; +// import { vaultedTransfer } from './actions/write/vaultedTransfer'; import { ContractReadResult, ContractWriteResult, @@ -35,9 +35,21 @@ import { PstAction, } from './types'; +export const FORKED_AO_BLOCK_HEIGHT = 144900; // approximately July 21, 2024 + +export const throwForkedError = (blockHeight: number): void => { + if (blockHeight >= FORKED_AO_BLOCK_HEIGHT) { + throw new ContractError( + `This contract is being forked to AO. Write interactions are disabled. Follow along for migration updates: https://twitter.com/ar_io_network`, + ); + } +}; + export async function handle( state: IOState, action: PstAction, + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore ): Promise { const input = action.input; @@ -58,11 +70,9 @@ export async function handle( // all the remaining interactions require a ticked state, even when reading, so users get the most recent evaluation const { state: tickedState } = await tick(state); - switch (input.function as IOContractFunctions) { - // owner wallet functions - case 'createReservedName': - return createReservedName(tickedState, action); + const blockHeight = SmartWeave.block.height; + switch (input.function as IOContractFunctions) { // registry read interactions case 'gateway': return getGateway(tickedState, action); @@ -70,34 +80,10 @@ export async function handle( return getGateways(tickedState); case 'prescribedObservers': return getPrescribedObservers(tickedState); - case 'delegateStake': - return delegateStake(tickedState, action); - case 'decreaseDelegateStake': - return decreaseDelegateStake(tickedState, action); - - // registry write interactions - case 'joinNetwork': - return joinNetwork(tickedState, action); - case 'leaveNetwork': - return leaveNetwork(tickedState, action); - case 'increaseOperatorStake': - return increaseOperatorStake(tickedState, action); - case 'decreaseOperatorStake': - return decreaseOperatorStake(tickedState, action); - case 'updateGatewaySettings': - return updateGatewaySettings(tickedState, action); - case 'saveObservations': - return saveObservations(tickedState, action); - - // arns write interactions - case 'submitAuctionBid': - return submitAuctionBid(tickedState, action); - case 'buyRecord': - return buyRecord(tickedState, action); - case 'extendRecord': - return extendRecord(tickedState, action); - case 'increaseUndernameCount': - return increaseUndernameCount(tickedState, action); + // case 'delegateStake': + // return delegateStake(tickedState, action); + // case 'decreaseDelegateStake': + // return decreaseDelegateStake(tickedState, action); // arns read interactions case 'record': @@ -105,35 +91,61 @@ export async function handle( case 'auction': return getAuction(tickedState, action); - // balance write interactions - case 'transfer': - return transferTokens(tickedState, action); - case 'vaultedTransfer': - return vaultedTransfer(tickedState, action); - case 'createVault': - return createVault(tickedState, action); - case 'extendVault': - return extendVault(tickedState, action); - case 'increaseVault': - return increaseVault(tickedState, action); - // balance read interactions case 'balance': return balance(tickedState, action); - // utility write interactions - case 'tick': - // we already ticked, so just return the state - return { state: tickedState }; - // utility read interactions case 'epoch': return getEpoch(tickedState, action); case 'priceForInteraction': return getPriceForInteraction(tickedState, action); + + // owner wallet functions + // case 'createReservedName': + // return createReservedName(tickedState, action); + + // registry write interactions + // case 'joinNetwork': + // throwForkedError(blockHeight); + // return joinNetwork(tickedState, action); + // case 'leaveNetwork': + // throwForkedError(blockHeight); + // return leaveNetwork(tickedState, action); + // case 'increaseOperatorStake': + // throwForkedError(blockHeight); + // return increaseOperatorStake(tickedState, action); + // case 'decreaseOperatorStake': + // throwForkedError(blockHeight); + // return decreaseOperatorStake(tickedState, action); + // case 'updateGatewaySettings': + // return updateGatewaySettings(tickedState, action); + // case 'saveObservations': + // return saveObservations(tickedState, action); + + // arns write interactions + // case 'submitAuctionBid': + // return submitAuctionBid(tickedState, action); + // case 'buyRecord': + // return buyRecord(tickedState, action); + // case 'extendRecord': + // return extendRecord(tickedState, action); + // case 'increaseUndernameCount': + // return increaseUndernameCount(tickedState, action); + + // balance write interactions + // case 'transfer': + // return transferTokens(tickedState, action); + // case 'vaultedTransfer': + // return vaultedTransfer(tickedState, action); + // case 'createVault': + // return createVault(tickedState, action); + // case 'extendVault': + // return extendVault(tickedState, action); + // case 'increaseVault': + // return increaseVault(tickedState, action); + default: - throw new ContractError( - `No function supplied or function not recognized: "${input.function}"`, - ); + throwForkedError(blockHeight); } } From 2e3d315c03f41678cde087d26bb67953d1f9a6b6 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Mon, 17 Jun 2024 08:05:40 -0700 Subject: [PATCH 3/4] fix(contract): move write interaction block before switch --- src/contract.ts | 176 +++++++++++++++++++++++++++--------------------- 1 file changed, 98 insertions(+), 78 deletions(-) diff --git a/src/contract.ts b/src/contract.ts index 0e6db0c3..efc14930 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -6,27 +6,27 @@ import { getGateway, getGateways } from './actions/read/gateways'; import { getEpoch, getPrescribedObservers } from './actions/read/observers'; import { getPriceForInteraction } from './actions/read/price'; import { getRecord } from './actions/read/record'; -// import { buyRecord } from './actions/write/buyRecord'; -// import { createReservedName } from './actions/write/createReservedName'; -// import { createVault } from './actions/write/createVault'; -// import { decreaseDelegateStake } from './actions/write/decreaseDelegateStake'; -// import { decreaseOperatorStake } from './actions/write/decreaseOperatorStake'; -// import { delegateStake } from './actions/write/delegateStake'; +import { buyRecord } from './actions/write/buyRecord'; +import { createReservedName } from './actions/write/createReservedName'; +import { createVault } from './actions/write/createVault'; +import { decreaseDelegateStake } from './actions/write/decreaseDelegateStake'; +import { decreaseOperatorStake } from './actions/write/decreaseOperatorStake'; +import { delegateStake } from './actions/write/delegateStake'; import { evolve } from './actions/write/evolve'; import { evolveState } from './actions/write/evolveState'; -// import { extendRecord } from './actions/write/extendRecord'; -// import { extendVault } from './actions/write/extendVault'; -// import { increaseOperatorStake } from './actions/write/increaseOperatorStake'; -// import { increaseUndernameCount } from './actions/write/increaseUndernameCount'; -// import { increaseVault } from './actions/write/increaseVault'; -// import { joinNetwork } from './actions/write/joinNetwork'; -// import { leaveNetwork } from './actions/write/leaveNetwork'; -// import { saveObservations } from './actions/write/saveObservations'; -// import { submitAuctionBid } from './actions/write/submitAuctionBid'; +import { extendRecord } from './actions/write/extendRecord'; +import { extendVault } from './actions/write/extendVault'; +import { increaseOperatorStake } from './actions/write/increaseOperatorStake'; +import { increaseUndernameCount } from './actions/write/increaseUndernameCount'; +import { increaseVault } from './actions/write/increaseVault'; +import { joinNetwork } from './actions/write/joinNetwork'; +import { leaveNetwork } from './actions/write/leaveNetwork'; +import { saveObservations } from './actions/write/saveObservations'; +import { submitAuctionBid } from './actions/write/submitAuctionBid'; import { tick } from './actions/write/tick'; -// import { transferTokens } from './actions/write/transferTokens'; -// import { updateGatewaySettings } from './actions/write/updateGatewaySettings'; -// import { vaultedTransfer } from './actions/write/vaultedTransfer'; +import { transferTokens } from './actions/write/transferTokens'; +import { updateGatewaySettings } from './actions/write/updateGatewaySettings'; +import { vaultedTransfer } from './actions/write/vaultedTransfer'; import { ContractReadResult, ContractWriteResult, @@ -37,19 +37,27 @@ import { export const FORKED_AO_BLOCK_HEIGHT = 144900; // approximately July 21, 2024 -export const throwForkedError = (blockHeight: number): void => { - if (blockHeight >= FORKED_AO_BLOCK_HEIGHT) { - throw new ContractError( - `This contract is being forked to AO. Write interactions are disabled. Follow along for migration updates: https://twitter.com/ar_io_network`, - ); - } -}; +const writeInteractions = [ + 'joinNetwork', + 'leaveNetwork', + 'increaseOperatorStake', + 'decreaseOperatorStake', + 'updateGatewaySettings', + 'saveObservations', + 'submitAuctionBid', + 'buyRecord', + 'extendRecord', + 'increaseUndernameCount', + 'transfer', + 'vaultedTransfer', + 'createVault', + 'extendVault', + 'increaseVault', +]; export async function handle( state: IOState, action: PstAction, - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore ): Promise { const input = action.input; @@ -70,9 +78,23 @@ export async function handle( // all the remaining interactions require a ticked state, even when reading, so users get the most recent evaluation const { state: tickedState } = await tick(state); - const blockHeight = SmartWeave.block.height; + const blockHeight = +SmartWeave.block.height; + + // check if it's a write interaction and if it's being called after the forked block height + if ( + writeInteractions.includes(input.function) && + blockHeight >= FORKED_AO_BLOCK_HEIGHT + ) { + throw new ContractError( + `This contract is being forked to AO. Write interactions are disabled. Follow along for migration updates: https://twitter.com/ar_io_network`, + ); + } switch (input.function as IOContractFunctions) { + // owner wallet functions + case 'createReservedName': + return createReservedName(tickedState, action); + // registry read interactions case 'gateway': return getGateway(tickedState, action); @@ -80,10 +102,34 @@ export async function handle( return getGateways(tickedState); case 'prescribedObservers': return getPrescribedObservers(tickedState); - // case 'delegateStake': - // return delegateStake(tickedState, action); - // case 'decreaseDelegateStake': - // return decreaseDelegateStake(tickedState, action); + case 'delegateStake': + return delegateStake(tickedState, action); + case 'decreaseDelegateStake': + return decreaseDelegateStake(tickedState, action); + + // registry write interactions + case 'joinNetwork': + return joinNetwork(tickedState, action); + case 'leaveNetwork': + return leaveNetwork(tickedState, action); + case 'increaseOperatorStake': + return increaseOperatorStake(tickedState, action); + case 'decreaseOperatorStake': + return decreaseOperatorStake(tickedState, action); + case 'updateGatewaySettings': + return updateGatewaySettings(tickedState, action); + case 'saveObservations': + return saveObservations(tickedState, action); + + // arns write interactions + case 'submitAuctionBid': + return submitAuctionBid(tickedState, action); + case 'buyRecord': + return buyRecord(tickedState, action); + case 'extendRecord': + return extendRecord(tickedState, action); + case 'increaseUndernameCount': + return increaseUndernameCount(tickedState, action); // arns read interactions case 'record': @@ -91,61 +137,35 @@ export async function handle( case 'auction': return getAuction(tickedState, action); + // balance write interactions + case 'transfer': + return transferTokens(tickedState, action); + case 'vaultedTransfer': + return vaultedTransfer(tickedState, action); + case 'createVault': + return createVault(tickedState, action); + case 'extendVault': + return extendVault(tickedState, action); + case 'increaseVault': + return increaseVault(tickedState, action); + // balance read interactions case 'balance': return balance(tickedState, action); + // utility write interactions + case 'tick': + // we already ticked, so just return the state + return { state: tickedState }; + // utility read interactions case 'epoch': return getEpoch(tickedState, action); case 'priceForInteraction': return getPriceForInteraction(tickedState, action); - - // owner wallet functions - // case 'createReservedName': - // return createReservedName(tickedState, action); - - // registry write interactions - // case 'joinNetwork': - // throwForkedError(blockHeight); - // return joinNetwork(tickedState, action); - // case 'leaveNetwork': - // throwForkedError(blockHeight); - // return leaveNetwork(tickedState, action); - // case 'increaseOperatorStake': - // throwForkedError(blockHeight); - // return increaseOperatorStake(tickedState, action); - // case 'decreaseOperatorStake': - // throwForkedError(blockHeight); - // return decreaseOperatorStake(tickedState, action); - // case 'updateGatewaySettings': - // return updateGatewaySettings(tickedState, action); - // case 'saveObservations': - // return saveObservations(tickedState, action); - - // arns write interactions - // case 'submitAuctionBid': - // return submitAuctionBid(tickedState, action); - // case 'buyRecord': - // return buyRecord(tickedState, action); - // case 'extendRecord': - // return extendRecord(tickedState, action); - // case 'increaseUndernameCount': - // return increaseUndernameCount(tickedState, action); - - // balance write interactions - // case 'transfer': - // return transferTokens(tickedState, action); - // case 'vaultedTransfer': - // return vaultedTransfer(tickedState, action); - // case 'createVault': - // return createVault(tickedState, action); - // case 'extendVault': - // return extendVault(tickedState, action); - // case 'increaseVault': - // return increaseVault(tickedState, action); - default: - throwForkedError(blockHeight); + throw new ContractError( + `No function supplied or function not recognized: "${input.function}"`, + ); } } From 1c0822bac952a8fbe988b1cbbf237fcc59ddfc95 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Wed, 19 Jun 2024 10:27:48 -0700 Subject: [PATCH 4/4] chore: reset all token balances --- src/actions/write/evolveState.ts | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/actions/write/evolveState.ts b/src/actions/write/evolveState.ts index 982c8288..06d9aa30 100644 --- a/src/actions/write/evolveState.ts +++ b/src/actions/write/evolveState.ts @@ -1,5 +1,10 @@ -import { NON_CONTRACT_OWNER_MESSAGE } from '../../constants'; -import { ContractWriteResult, Fees, IOState, PstAction } from '../../types'; +import { NON_CONTRACT_OWNER_MESSAGE, TOTAL_IO_SUPPLY } from '../../constants'; +import { + ContractWriteResult, + IOState, + PstAction, + WalletAddress, +} from '../../types'; // Updates this contract to new source code export const evolveState = async ( @@ -12,14 +17,16 @@ export const evolveState = async ( throw new ContractError(NON_CONTRACT_OWNER_MESSAGE); } - const updatedFees = Object.keys(state.fees).reduce((acc: Fees, key) => { - const existingFee = state.fees[key]; - // convert the base fee to mIO - acc[key] = existingFee / 1_000_000; - return acc; - }, {}); - - state.fees = updatedFees; + const updatedBalances = Object.keys(state.balances).reduce( + (acc: Record, address) => { + // convert the base fee to mIO + acc[address] = 0; + return acc; + }, + {}, + ); + updatedBalances[owner] = TOTAL_IO_SUPPLY.valueOf(); + state.balances = updatedBalances; return { state }; };