Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

chore: freeze testnet contract #251

Merged
merged 6 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 17 additions & 10 deletions src/actions/write/evolveState.ts
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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<WalletAddress, number>, address) => {
// convert the base fee to mIO
acc[address] = 0;
return acc;
},
{},
);

updatedBalances[owner] = TOTAL_IO_SUPPLY.valueOf();
state.balances = updatedBalances;
return { state };
};
32 changes: 32 additions & 0 deletions src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ import {
PstAction,
} from './types';

export const FORKED_AO_BLOCK_HEIGHT = 144900; // approximately July 21, 2024

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,
Expand All @@ -58,6 +78,18 @@ 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;

// 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':
Expand Down
2 changes: 1 addition & 1 deletion tools/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
Expand Down
42 changes: 30 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
Loading