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

chore: devnet to testnet #242

Merged
merged 5 commits into from
Apr 26, 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
28 changes: 28 additions & 0 deletions src/actions/read/price.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@ describe('getPriceForInteraction', () => {
)
.multiply(0.5),
],
[
'should return the correct price for buyRecord of a reserved name when the caller is not the reserved target',
{
...state,
reserved: {
'test-reserved-name': {
target: 'test-target',
endTimestamp: +SmartWeave.block.timestamp + SECONDS_IN_A_YEAR,
},
},
},
{
caller: 'test-caller',
input: {
interactionName: 'buyRecord' as InteractionsWithFee,
name: 'test-reserved-name',
type: 'permabuy',
},
},
new mIOToken(GENESIS_FEES['test-reserved-name'.length]).plus(
new mIOToken(
// permabuy so 10 year annual renewal fee
GENESIS_FEES['test-reserved-name'.length],
)
.multiply(10)
.multiply(0.2),
),
],
[
'should return the correct price for extendRecord when demand factor is 1',
{
Expand Down
4 changes: 2 additions & 2 deletions src/actions/read/price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function getPriceForInteraction(
});
}
assertAvailableRecord({
caller,
caller: undefined, // stub the caller so we still get the price
name,
records: state.records,
reserved: state.reserved,
Expand All @@ -87,7 +87,7 @@ export function getPriceForInteraction(
const { name, type } = new AuctionBid(parsedInput);
const auction = state.auctions[name];
assertAvailableRecord({
caller,
caller: undefined, // stub the caller so we still get the price
name,
records: state.records,
reserved: state.reserved,
Expand Down
22 changes: 10 additions & 12 deletions src/actions/write/evolveState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BLOCKS_PER_DAY, NON_CONTRACT_OWNER_MESSAGE } from '../../constants';
import { ContractWriteResult, IOState, PstAction } from '../../types';
import { NON_CONTRACT_OWNER_MESSAGE } from '../../constants';
import { ContractWriteResult, Fees, IOState, PstAction } from '../../types';

// Updates this contract to new source code
export const evolveState = async (
Expand All @@ -12,16 +12,14 @@ export const evolveState = async (
throw new ContractError(NON_CONTRACT_OWNER_MESSAGE);
}

for (const [address, gateway] of Object.entries(state.gateways)) {
if (gateway.status === 'leaving') {
// fix the expiration to 21 days (was set at 90)
const currentEndFor90Days = gateway.end;
const correctEndFor21Days =
currentEndFor90Days - 69 * BLOCKS_PER_DAY + 4 * BLOCKS_PER_DAY; // add 4 days given the mistake
state.gateways[address].end = correctEndFor21Days;
state.gateways[address].vaults[address].end = correctEndFor21Days;
}
}
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;

return { state };
};
5 changes: 5 additions & 0 deletions src/records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ export function assertAvailableRecord({
return;
}

// if caller is not provided, assume a read interaction and do not throw
if (!caller) {
return;
}

if (isReserved) {
throw new ContractError(ARNS_NAME_RESERVED_MESSAGE);
}
Expand Down
82 changes: 45 additions & 37 deletions tools/cli/reserved-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,56 @@ import questions from './questions';
validity: true,
});

const payload = {
function: 'createReservedName',
target: reservedName.target,
name: reservedName.name,
endTimestamp: reservedName.endTimestamp,
};

let attempts = 0;
let lastErrorMessage;
let result;
while (attempts < 3) {
const dryWrite = await contract.dryWrite(payload);
if (dryWrite.type === 'error' || dryWrite.errorMessage) {
lastErrorMessage = dryWrite.errorMessage ?? 'Unknown error';
attempts++;
await new Promise((resolve) => setTimeout(resolve, 1000)); // wait one second before retrying
} else {
// success - break
result = dryWrite.state.reserved[reservedName.name];
lastErrorMessage = undefined;
break;
}
}

if (lastErrorMessage) {
console.error('Error:', lastErrorMessage);
return;
}

const confirm = await inquirer.prompt({
name: 'confirm',
type: 'confirm',
message: `CONFIRM RESERVED NAME DETAILS? ${JSON.stringify(reservedName)} >`,
});

if (confirm.confirm) {
const payload = {
function: 'createReservedName',
target: reservedName.target,
message: `CONFIRM RESERVED NAME DETAILS? ${JSON.stringify({
name: reservedName.name,
endTimestamp: reservedName.endTimestamp,
};

let attempts = 0;
let lastErrorMessage;
while (attempts < 3) {
const dryWrite = await contract.dryWrite(payload);
if (dryWrite.type === 'error' || dryWrite.errorMessage) {
lastErrorMessage = dryWrite.errorMessage ?? 'Unknown error';
attempts++;
await new Promise((resolve) => setTimeout(resolve, 1000)); // wait one second before retrying
} else {
// success - break
lastErrorMessage = undefined;
break;
}
}
...result,
})} >`,
});

if (lastErrorMessage) {
console.error('Error:', lastErrorMessage);
return;
}
if (!confirm.confirm) {
console.log('User cancelled the transaction.');
return;
}

console.log('Submitting transaction to create reserved name...');
console.log('Submitting transaction to create reserved name...');

const txId = await contract.writeInteraction(payload, {
disableBundling: true,
});
// eslint-disable-next-line
console.log(
`Successfully submitted interaction to create reserved name. TxId: ${txId?.originalTxId}`,
);
}
const txId = await contract.writeInteraction(payload, {
disableBundling: true,
});
// eslint-disable-next-line
console.log(
`Successfully submitted interaction to create reserved name. TxId: ${txId?.originalTxId}`,
);
})();
4 changes: 3 additions & 1 deletion tools/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import { DeployPlugin } from 'warp-contracts-plugin-deploy';
import { keyfile } from './constants';

// gate the contract txId
export const arnsContractTxId = 'bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U';
export const arnsContractTxId =
process.env.ARNS_CONTRACT_TX_ID ??
'bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U';

// intended to be run before any scripts
export const initialize = (): void => {
Expand Down
Loading