Skip to content

Commit

Permalink
feat(ownable undernames): added support for under_ant resolution, min…
Browse files Browse the repository at this point in the history
…ting, and purchase of undernames with multitoken configuration, as well as reservation support
  • Loading branch information
atticusofsparta committed Dec 22, 2023
1 parent df933a8 commit 8ddbe48
Show file tree
Hide file tree
Showing 25 changed files with 4,646 additions and 7 deletions.
106 changes: 106 additions & 0 deletions build-undername-leasing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const fs = require('fs');
const path = require('path');
const { build } = require('esbuild');
const replace = require('replace-in-file');
const Ajv = require('ajv');
const standaloneCode = require('ajv/dist/standalone').default;
const contracts = ['contract-undername-leasing.ts'];
const {
balanceSchema,
removeControllerSchema,
setControllerSchema,
setNameSchema,
setTickerSchema,
setRecordSchema,
removeRecordSchema,
transferSchema,
evolveSchema,
mintSchema,
setMintingPairSchema,
buyRecordSchema,
setReservedRecordsSchema,
removeReservedRecordsSchema,
} = require('./schemas');

// build our validation source code
const ajv = new Ajv({
schemas: [
balanceSchema,
removeControllerSchema,
setControllerSchema,
setNameSchema,
setTickerSchema,
setRecordSchema,
removeRecordSchema,
transferSchema,
evolveSchema,
mintSchema,
setMintingPairSchema,
buyRecordSchema,
setReservedRecordsSchema,
removeReservedRecordsSchema,
],
code: { source: true, esm: true },
});

const moduleCode = standaloneCode(ajv, {
validateSetRecord: '#/definitions/setRecord',
validateRemoveRecord: '#/definitions/removeRecord',
validateSetController: '#/definitions/setController',
validateRemoveController: '#/definitions/removeController',
validateSetName: '#/definitions/setName',
validateSetTicker: '#/definitions/setTicker',
validateBalance: '#/definitions/balance',
validateTransferTokens: '#/definitions/transfer',
validateEvolve: '#/definitions/evolve',
validateMint: '#/definitions/mint',
validateSetMintingPair: '#/definitions/setMintingPair',
validateBuyRecord: '#/definitions/buyRecord',
validateSetReservedRecords: '#/definitions/setReservedRecords',
validateRemoveReservedRecords: '#/definitions/removeReservedRecords',
});

// Now you can write the module code to file
fs.writeFileSync(path.join(__dirname, '/src/validations-undername-leasing.js'), moduleCode);

build({
entryPoints: contracts.map((source) => {
return `./src/${source}`;
}),
outdir: './dist',
minify: false,
bundle: true,
format: 'iife',
packages: 'external',
tsconfig: './tsconfig.json',
})
.catch(() => process.exit(1))
// note: SmartWeave SDK currently does not support files in IIFE bundle format, so we need to remove the "iife" part ;-)
// update: it does since 0.4.31, but because viewblock.io is still incompatibile with this version, leaving as is for now.
.finally(() => {
const files = contracts.map((source) => {
return `./dist${source}`.replace('.ts', '.js');
});
replace.sync({
files: files,
from: [/\(\(\) => {/g, /}\)\(\);/g],
to: '',
countMatches: true,
});
});
53 changes: 52 additions & 1 deletion globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,56 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
declare let SmartWeave: any;
type TransactionOrigin = 'L1' | 'L2';

interface SWTransaction {
readonly id: string;
readonly owner: string;
readonly target: string;
readonly tags: {name: string, value: string}[];
readonly sortKey: string;
readonly dryRun: boolean;
readonly quantity: number;
readonly reward: number;
readonly origin: TransactionOrigin;
}

interface SWBlock {
readonly height: number;
readonly indep_hash: string;
readonly timestamp: number;
}

type SmartWeaveGlobal = {
gasUsed: number;
gasLimit: number;
transaction: SWTransaction;
block: SWBlock;
vrf: any; // SWVrf replaced with any
evaluationOptions: any; // EvaluationOptions replaced with any
arweave: Pick<any, 'ar' | 'wallets' | 'utils' | 'crypto'>; // Arweave replaced with any
contract: {
id: string;
owner: string;
};
unsafeClient: any; // Arweave replaced with any
baseArweaveUrl: string;
safeArweaveGet: (input: RequestInfo | URL, init?: RequestInit) => Promise<unknown>;
contracts: {
readContractState: (contractId: string, returnValidity?: boolean) => Promise<any>;
viewContractState: (contractId: string, input: any) => Promise<any>;
write: (contractId: string, input: any) => Promise<any>;
refreshState: () => Promise<any>;
};
extensions: any;
_activeTx?: any; // GQLNodeInterface replaced with any
caller?: string;
kv: any; // KV replaced with any
useGas(gas: number): void;
getBalance(address: string, height?: number): Promise<string>;
}



declare let SmartWeave: SmartWeaveGlobal;
declare let ContractError: any;
89 changes: 89 additions & 0 deletions initial-state-undername-leasing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"ticker": "ANT-OWNABLE-UNDERNAMES",
"name": "Arweave Name Token v0.0.0",
"owner": "",
"controllers": [],
"fees": {
"1": 5000000,
"2": 500000,
"3": 100000,
"4": 25000,
"5": 10000,
"6": 5000,
"7": 2500,
"8": 1500,
"9": 1250,
"10": 1250,
"11": 1250,
"12": 1250,
"13": 1000,
"14": 1000,
"15": 1000,
"16": 1000,
"17": 1000,
"18": 1000,
"19": 1000,
"20": 1000,
"21": 1000,
"22": 1000,
"23": 1000,
"24": 1000,
"25": 1000,
"26": 1000,
"27": 1000,
"28": 1000,
"29": 1000,
"30": 1000,
"31": 1000,
"32": 1000,
"33": 1000,
"34": 1000,
"35": 1000,
"36": 1000,
"37": 1000,
"38": 1000,
"39": 1000,
"40": 1000,
"41": 1000,
"42": 1000,
"43": 1000,
"44": 1000,
"45": 1000,
"46": 1000,
"47": 1000,
"48": 1000,
"49": 1000,
"50": 1000,
"51": 1000,
"52": 1000,
"53": 1000,
"54": 1000,
"55": 1000,
"56": 1000,
"57": 1000,
"58": 1000,
"59": 1000,
"60": 1000,
"61": 1000
},
"reserved": {
"subDomains": [],
"pattern": ""
},
"records": {
"@": {
"transactionId": "",
"ttlSeconds": 900
}
},
"balances": {
"": 0
},
"totalSupply": 0,
"supportedTokens": {
"AR": {
"conversionRate": 1
}
},
"evolve": null
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.2.0",
"private": true,
"scripts": {
"build": "yarn clean && node build.js && tsc --noEmit",
"build": "yarn clean && node build.js && node build-undername-leasing.js && tsc --noEmit",
"format:check": "prettier . --check --cache",
"format:fix": "prettier . --write",
"lint:check": "eslint .",
Expand Down
40 changes: 40 additions & 0 deletions schemas/buyRecord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const buyRecordSchema = {
$id: '#/definitions/buyRecord',
type: 'object',
properties: {
function: {
type: 'string',
const: 'buyRecord',
},
subDomain: {
type: 'string',
pattern: '^([a-zA-Z0-9][a-zA-Z0-9-_]{0,59}[a-zA-Z0-9]|[a-zA-Z0-9]{1}|@)$',
},
contractTxId: {
type: 'string',
pattern: '^(atomic|[a-zA-Z0-9-_]{43})$'
}
},
required: ['subDomain', 'contractTxId'],
additionalProperties: false,
};

module.exports = {
buyRecordSchema,
};
5 changes: 5 additions & 0 deletions schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ module.exports = {
removeControllerSchema: require('./removeController').removeControllerSchema,
balanceSchema: require('./balance').balanceSchema,
transferSchema: require('./transfer').transferSchema,
mintSchema: require('./mint').mintSchema,
setMintingPairSchema: require('./setMintingPair').setMintingPairSchema,
buyRecordSchema: require('./buyRecord').buyRecordSchema,
setReservedRecordsSchema: require('./setReservedRecords').setReservedRecordsSchema,
removeReservedRecordsSchema: require('./removeReservedRecords').removeReservedRecordsSchema,
};
39 changes: 39 additions & 0 deletions schemas/mint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const mintSchema = {
$id: '#/definitions/mint',
type: 'object',
properties: {
function: {
type: 'string',
const: 'mint',
},
type: {
type: 'string',
},
tokenId: {
type: 'string',
pattern:'^[a-zA-Z0-9_-]{43}$'
}
},
required: ['type', 'tokenId'],
additionalProperties: false,
};

module.exports = {
mintSchema,
};
39 changes: 39 additions & 0 deletions schemas/removeReservedRecords.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const removeReservedRecordsSchema = {
$id: '#/definitions/removeReservedRecords',
type: 'object',
properties: {
function: {
type: 'string',
const: 'removeReservedRecords',
},
subDomains: {
type: 'array',
items: {
type: 'string',
pattern: '^([a-zA-Z0-9][a-zA-Z0-9-_]{0,59}[a-zA-Z0-9]|[a-zA-Z0-9]{1})$'
},
},
},
required: ['subDomains'],
additionalProperties: false,
};

module.exports = {
removeReservedRecordsSchema,
};
Loading

0 comments on commit 8ddbe48

Please sign in to comment.