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

Commit

Permalink
Merge branch 'develop' into PE-4423-Remove-Extra-Network-Join-Code
Browse files Browse the repository at this point in the history
  • Loading branch information
vilenarios authored Aug 18, 2023
2 parents eeefd1a + a5bf2db commit 1003f85
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ validations.mjs

# keys
**key**.json
wallets

# warp
cache
Expand Down
19 changes: 17 additions & 2 deletions json_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,24 @@
"properties": {
"tier": { "type": "string", "format": "uuid" },
"contractTxID": { "type": "string", "format": "uuid" },
"endTimestamp": { "type": "integer" }
"endTimestamp": { "type": "integer" },
"startTimestamp": { "type": "integer" }
},
"required": ["tier", "contractTxID", "endTimestamp"],
"required": ["tier", "contractTxID", "startTimestamp"],
"additionalProperties": false
}
},
"auctions": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"tier": { "type": "string", "format": "uuid" },
"contractTxID": { "type": "string", "format": "uuid" },
"endTimestamp": { "type": "integer" },
"startTimestamp": { "type": "integer" }
},
"required": ["tier", "contractTxID", "startTimestamp"],
"additionalProperties": false
}
},
Expand Down
2 changes: 1 addition & 1 deletion schemas/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const auctionBidSchema = {
},
name: {
type: 'string',
pattern: '^([a-zA-Z0-9][a-zA-Z0-9-]{0,30}[a-zA-Z0-9]|[a-zA-Z0-9]{1})$',
pattern: '^([a-zA-Z0-9][a-zA-Z0-9-]{0,49}[a-zA-Z0-9]|[a-zA-Z0-9]{1})$',
},
qty: {
type: 'number',
Expand Down
2 changes: 1 addition & 1 deletion schemas/buyRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const buyRecordSchema = {
},
name: {
type: 'string',
pattern: '^([a-zA-Z0-9][a-zA-Z0-9-]{0,30}[a-zA-Z0-9]|[a-zA-Z0-9]{1})$',
pattern: '^([a-zA-Z0-9][a-zA-Z0-9-]{0,49}[a-zA-Z0-9]|[a-zA-Z0-9]{1})$',
},
contractTxId: {
type: 'string',
Expand Down
1 change: 1 addition & 0 deletions src/actions/write/buyRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export const buyRecord = (
contractTxId,
tier,
type,
startTimestamp: +SmartWeave.block.timestamp,
// only include timestamp on lease
...(type === 'lease' ? { endTimestamp } : {}),
};
Expand Down
2 changes: 2 additions & 0 deletions src/actions/write/submitAuctionBid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ export const submitAuctionBid = (
contractTxId: existingAuction.contractTxId,
tier: existingAuction.tier,
type: existingAuction.type,
startTimestamp: +SmartWeave.block.timestamp,
// only include timestamp on lease
// something to think about - what if a ticking of state never comes? what do we set endTimestamp to?
...(existingAuction.type === 'lease' ? { endTimestamp } : {}),
Expand Down Expand Up @@ -330,6 +331,7 @@ export const submitAuctionBid = (
contractTxId: contractTxId, // only update the new contract tx id
tier: existingAuction.tier,
type: existingAuction.type,
startTimestamp: +SmartWeave.block.timestamp, // overwrite initial start timestamp
// only include timestamp on lease, endTimestamp is easy in this situation since it was a second interaction that won it
...(existingAuction.type === 'lease' ? { endTimestamp } : {}),
};
Expand Down
22 changes: 21 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AuctionSettings } from './types';

export const MAX_YEARS = 5; // the maximum amount of years an arns name could be leased for
export const MAX_NAME_LENGTH = 32; // the maximum length of an arns name
export const MAX_NAME_LENGTH = 51; // the maximum length of an arns name
export const MAX_NOTE_LENGTH = 256; // the maximum size of a note field
export const MAX_GATEWAY_LABEL_LENGTH = 16; // the maximum size of a label field
export const MAX_PORT_NUMBER = 65535; // the default end port of tcp/udp port numbers
Expand All @@ -22,6 +22,7 @@ export const MAX_ALLOWED_EVOLUTION_DELAY = 720 * 30;
export const MINIMUM_ALLOWED_EVOLUTION_DELAY = 3; // 3 blocks for testing purposes, but should be 720 * 7; // 720 blocks per day times 7 days
export const MINIMUM_ALLOWED_NAME_LENGTH = 5; // names less than 5 characters are reserved for auction
export const UNDERNAMES_COUNT = 10;
export const RARITY_MULTIPLIER_HALVENING = 25;
export const ALLOWED_ACTIVE_TIERS = [1, 2, 3];
export const ANNUAL_PERCENTAGE_FEE = 0.1; // 10% of cost of name
export const UNDERNAME_REGISTRATION_IO_FEE = 1; // 1 IO token per undername
Expand Down Expand Up @@ -109,6 +110,25 @@ export const FEE_STRUCTURE = {
'30': 125,
'31': 100,
'32': 50,
'33': 50,
'34': 50,
'35': 50,
'36': 50,
'37': 50,
'38': 50,
'39': 50,
'40': 50,
'41': 50,
'42': 50,
'43': 50,
'44': 50,
'45': 50,
'46': 50,
'47': 50,
'48': 50,
'49': 50,
'50': 50,
'51': 50,
};
export const AUCTION_SETTINGS_ID =
'3IkWJ-0HdwuATDhBXuJRm0bWspXOOkRjxTm-5R2xRbw';
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export type AllowedProtocols = 'http' | 'https';

export type ArNSName = {
contractTxId: string; // The ANT Contract used to manage this name
startTimestamp: number; // At what unix time (seconds since epoch) the lease starts
endTimestamp?: number; // At what unix time (seconds since epoch) the lease ends
tier: string; // The id of the tier selected at time of purchased
type: 'lease' | 'permabuy';
Expand Down
8 changes: 6 additions & 2 deletions src/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ANNUAL_PERCENTAGE_FEE,
MINIMUM_ALLOWED_NAME_LENGTH,
RARITY_MULTIPLIER_HALVENING,
} from './constants';
import { Fees, ServiceTier } from './types';

Expand Down Expand Up @@ -58,11 +59,14 @@ export function calculatePermabuyFee(
// e.g. name is 7 characters - this would be 0
// name is 2 characters - this would 8
const getMultiplier = (): number => {
if (name.length >= 25) {
if (name.length >= RARITY_MULTIPLIER_HALVENING) {
return 0.5; // cut the price in half
}
// names between 5 and 24 characters (inclusive)
if (name.length >= MINIMUM_ALLOWED_NAME_LENGTH && name.length < 25) {
if (
name.length >= MINIMUM_ALLOWED_NAME_LENGTH &&
name.length < RARITY_MULTIPLIER_HALVENING
) {
return 1; // e.g. it's the cost of a 10 year lease
}
// short names
Expand Down
3 changes: 3 additions & 0 deletions tests/auctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ describe('Auctions', () => {
expect(records[auctionBid.name]).toEqual({
contractTxId: ANT_CONTRACT_IDS[1],
endTimestamp: expect.any(Number),
startTimestamp: expect.any(Number),
tier: tiers.current[0],
type: 'lease',
});
Expand Down Expand Up @@ -530,6 +531,7 @@ describe('Auctions', () => {
contractTxId: ANT_CONTRACT_IDS[1],
tier: tiers.current[0],
type: 'permabuy',
startTimestamp: expect.any(Number),
});
expect(auctions[auctionBid.name]).toBeUndefined();
expect(balances[winnerAddress]).toEqual(
Expand Down Expand Up @@ -616,6 +618,7 @@ describe('Auctions', () => {
tier: tiers.current[0],
type: 'lease',
endTimestamp: expect.any(Number),
startTimestamp: expect.any(Number),
});
const floorToBidDifference = winningBidQty - auctionObj.floorPrice;
expect(balances[nonContractOwnerAddress]).toEqual(
Expand Down
5 changes: 5 additions & 0 deletions tests/records.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('Records', () => {
tier: expectedTierObj,
name: 'name1',
endTimestamp: expect.any(Number),
startTimestamp: expect.any(Number),
contractTxID: expect.any(String),
};
expect(record).not.toBe(undefined);
Expand Down Expand Up @@ -115,6 +116,7 @@ describe('Records', () => {
contractTxId: ANT_CONTRACT_IDS[0],
tier: tiers.current[0],
endTimestamp: expect.any(Number),
startTimestamp: expect.any(Number),
type: 'lease',
});
expect(balances[nonContractOwnerAddress]).toEqual(
Expand Down Expand Up @@ -161,6 +163,7 @@ describe('Records', () => {
contractTxId: ANT_CONTRACT_IDS[0],
tier: tiers.current[0],
endTimestamp: expect.any(Number),
startTimestamp: expect.any(Number),
type: 'lease',
});
expect(balances[nonContractOwnerAddress]).toEqual(
Expand Down Expand Up @@ -207,6 +210,7 @@ describe('Records', () => {
contractTxId: ANT_CONTRACT_IDS[0],
tier: tiers.current[0],
type: 'permabuy',
startTimestamp: expect.any(Number),
});
expect(balances[nonContractOwnerAddress]).toEqual(
prevBalance - expectedPurchasePrice,
Expand Down Expand Up @@ -737,6 +741,7 @@ describe('Records', () => {
contractTxId: ANT_CONTRACT_IDS[0],
tier: tiers.current[0],
endTimestamp: expect.any(Number),
startTimestamp: expect.any(Number),
type: 'lease',
});
expect(cachedValue.errorMessages[writeInteraction!.originalTxId]).toBe(
Expand Down
1 change: 1 addition & 0 deletions tests/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function createRecords(tiers: string[], count = 3) {
tier: tiers[0],
contractTxID: ANT_CONTRACT_IDS[0],
endTimestamp: new Date('01/01/2025').getTime() / 1000,
startTimestamp: Date.now(),
};
records[name] = obj;
}
Expand Down

0 comments on commit 1003f85

Please sign in to comment.