Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: standardize ARIOtoMARIO PE-7198 #294

Merged
merged 1 commit into from
Dec 20, 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 spec/epochs_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local testSettings = {
delegateRewardShareRatio = 0,
}
local startTimestamp = 1704092400000
local protocolBalance = 500000000 * 1000000
local protocolBalance = constants.ARIOToMARIO(500000000)
local hashchain = "NGU1fq_ssL9m6kRbRU1bqiIDBht79ckvAwRMGElkSOg" -- base64 of "some sample hash"
Comment on lines -16 to 17
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could go further into _spec files -- lots of floating numbers in arns_spec but diff gets out of control quick


describe("epochs", function()
Expand Down
117 changes: 62 additions & 55 deletions src/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ constants.oneWeekMs = constants.oneDayMs * 7
constants.twoWeeksMs = constants.oneWeekMs * 2
constants.oneYearMs = 31536000 * 1000

constants.mARIOPerARIO = 1000000

--- @param ARIO number
--- @return mARIO
function constants.ARIOToMARIO(ARIO)
return ARIO * constants.mARIOPerARIO
end

-- EPOCHS
constants.defaultEpochDurationMs = constants.oneDayMs
constants.maximumRewardRate = 0.001
Expand All @@ -19,10 +27,9 @@ constants.rewardDecayLastEpoch = 547
-- GAR
constants.DEFAULT_UNDERNAME_COUNT = 10
constants.DEADLINE_DURATION_MS = constants.oneHourMs
constants.totalTokenSupply = 1000000000 * 1000000 -- 1 billion tokens
constants.totalTokenSupply = constants.ARIOToMARIO(1000000000) -- 1 billion tokens
constants.MIN_EXPEDITED_WITHDRAWAL_PENALTY_RATE = 0.10 -- the minimum penalty rate for an expedited withdrawal (10% of the amount being withdrawn)
constants.MAX_EXPEDITED_WITHDRAWAL_PENALTY_RATE = 0.50 -- the maximum penalty rate for an expedited withdrawal (50% of the amount being withdrawn)
constants.mARIOPerARIO = 1000000
constants.minimumWithdrawalAmount = constants.mARIOPerARIO -- the minimum amount that can be withdrawn from the GAR
constants.redelegationFeeResetIntervalMs = constants.defaultEpochDurationMs * 7 -- 7 epochs
constants.maxDelegateRewardShareRatio = 95 -- 95% of rewards can be shared with delegates
Expand All @@ -43,7 +50,7 @@ constants.ANNUAL_PERCENTAGE_FEE = 0.2 -- 20%
constants.ARNS_NAME_DOES_NOT_EXIST_MESSAGE = "Name not found in the ArNS Registry!"
constants.UNDERNAME_LEASE_FEE_PERCENTAGE = 0.001
constants.UNDERNAME_PERMABUY_FEE_PERCENTAGE = 0.005
constants.PRIMARY_NAME_REQUEST_COST = 10000000 -- 10 ARIO
constants.PRIMARY_NAME_REQUEST_COST = constants.ARIOToMARIO(10) -- 10 ARIO
constants.gracePeriodMs = constants.defaultEpochDurationMs * 14 -- 14 epochs
constants.maxLeaseLengthYears = 5
constants.returnedNamePeriod = constants.defaultEpochDurationMs * 14 -- 14 epochs
Expand All @@ -67,63 +74,63 @@ constants.demandSettings = {
}

-- VAULTS
constants.MIN_VAULT_SIZE = 100000000 -- 100 ARIO
constants.MIN_VAULT_SIZE = constants.ARIOToMARIO(100) -- 100 ARIO
constants.MAX_TOKEN_LOCK_TIME_MS = 12 * 365 * 24 * 60 * 60 * 1000 -- The maximum amount of blocks tokens can be locked in a vault (12 years of blocks)
constants.MIN_TOKEN_LOCK_TIME_MS = 14 * 24 * 60 * 60 * 1000 -- The minimum amount of blocks tokens can be locked in a vault (14 days of blocks)

-- ARNS FEES
constants.genesisFees = {
[1] = 2000000000000,
[2] = 200000000000,
[3] = 40000000000,
[4] = 10000000000,
[5] = 4000000000,
[6] = 2000000000,
[7] = 1000000000,
[8] = 600000000,
[9] = 500000000,
[10] = 500000000,
[11] = 500000000,
[12] = 500000000,
[13] = 400000000,
[14] = 400000000,
[15] = 400000000,
[16] = 400000000,
[17] = 400000000,
[18] = 400000000,
[19] = 400000000,
[20] = 400000000,
[21] = 400000000,
[22] = 400000000,
[23] = 400000000,
[24] = 400000000,
[25] = 400000000,
[26] = 400000000,
[27] = 400000000,
[28] = 400000000,
[29] = 400000000,
[30] = 400000000,
[31] = 400000000,
[32] = 400000000,
[33] = 400000000,
[34] = 400000000,
[35] = 400000000,
[36] = 400000000,
[37] = 400000000,
[38] = 400000000,
[39] = 400000000,
[40] = 400000000,
[41] = 400000000,
[42] = 400000000,
[43] = 400000000,
[44] = 400000000,
[45] = 400000000,
[46] = 400000000,
[47] = 400000000,
[48] = 400000000,
[49] = 400000000,
[50] = 400000000,
[51] = 400000000,
[1] = constants.ARIOToMARIO(2000000),
[2] = constants.ARIOToMARIO(200000),
[3] = constants.ARIOToMARIO(40000),
[4] = constants.ARIOToMARIO(10000),
[5] = constants.ARIOToMARIO(4000),
[6] = constants.ARIOToMARIO(2000),
[7] = constants.ARIOToMARIO(1000),
[8] = constants.ARIOToMARIO(600),
[9] = constants.ARIOToMARIO(500),
[10] = constants.ARIOToMARIO(500),
[11] = constants.ARIOToMARIO(500),
[12] = constants.ARIOToMARIO(500),
[13] = constants.ARIOToMARIO(400),
[14] = constants.ARIOToMARIO(400),
[15] = constants.ARIOToMARIO(400),
[16] = constants.ARIOToMARIO(400),
[17] = constants.ARIOToMARIO(400),
[18] = constants.ARIOToMARIO(400),
[19] = constants.ARIOToMARIO(400),
[20] = constants.ARIOToMARIO(400),
[21] = constants.ARIOToMARIO(400),
[22] = constants.ARIOToMARIO(400),
[23] = constants.ARIOToMARIO(400),
[24] = constants.ARIOToMARIO(400),
[25] = constants.ARIOToMARIO(400),
[26] = constants.ARIOToMARIO(400),
[27] = constants.ARIOToMARIO(400),
[28] = constants.ARIOToMARIO(400),
[29] = constants.ARIOToMARIO(400),
[30] = constants.ARIOToMARIO(400),
[31] = constants.ARIOToMARIO(400),
[32] = constants.ARIOToMARIO(400),
[33] = constants.ARIOToMARIO(400),
[34] = constants.ARIOToMARIO(400),
[35] = constants.ARIOToMARIO(400),
[36] = constants.ARIOToMARIO(400),
[37] = constants.ARIOToMARIO(400),
[38] = constants.ARIOToMARIO(400),
[39] = constants.ARIOToMARIO(400),
[40] = constants.ARIOToMARIO(400),
[41] = constants.ARIOToMARIO(400),
[42] = constants.ARIOToMARIO(400),
[43] = constants.ARIOToMARIO(400),
[44] = constants.ARIOToMARIO(400),
[45] = constants.ARIOToMARIO(400),
[46] = constants.ARIOToMARIO(400),
[47] = constants.ARIOToMARIO(400),
[48] = constants.ARIOToMARIO(400),
[49] = constants.ARIOToMARIO(400),
[50] = constants.ARIOToMARIO(400),
[51] = constants.ARIOToMARIO(400),
}

-- General
Expand Down
4 changes: 2 additions & 2 deletions src/gar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ GatewayRegistrySettings = {
maxTenureWeight = 4,
},
operators = {
minStake = 10000 * 1000000, -- 10,000 ARIO
minStake = constants.ARIOToMARIO(10000), -- 10,000 ARIO
withdrawLengthMs = 90 * 24 * 60 * 60 * 1000, -- 90 days to lower operator stake
leaveLengthMs = 90 * 24 * 60 * 60 * 1000, -- 90 days that balance will be vaulted
failedEpochCountMax = 30, -- number of epochs failed before marked as leaving
failedEpochSlashRate = 0.2, -- 20% of stake is returned to protocol balance
},
delegates = {
minStake = 10 * 1000000, -- 10 ARIO
minStake = constants.ARIOToMARIO(10), -- 10 ARIO
withdrawLengthMs = 90 * 24 * 60 * 60 * 1000, -- 90 days
},
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Protocol = Protocol or ao.env.Process.Id
Balances = Balances or {}
if not Balances[Protocol] then -- initialize the balance for the process id
Balances = {
[Protocol] = math.floor(50000000 * 1000000), -- 50M ARIO
[Owner] = math.floor(constants.totalTokenSupply - (50000000 * 1000000)), -- 950M ARIO
[Protocol] = math.floor(constants.ARIOToMARIO(50000000)), -- 50M ARIO
[Owner] = math.floor(constants.totalTokenSupply - (constants.ARIOToMARIO(50000000))), -- 950M ARIO
}
end
Vaults = Vaults or {}
Expand Down
8 changes: 4 additions & 4 deletions tests/handlers.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { handle } from './helpers.mjs';
import { ARIOToMARIO, handle } from './helpers.mjs';
import { describe, it } from 'node:test';
import assert from 'node:assert';

Expand Down Expand Up @@ -54,7 +54,7 @@ describe('handlers', async () => {
const tokenSupplyData = JSON.parse(
tokenSupplyResult.Messages?.[0]?.Data,
);
assert.ok(tokenSupplyData === 1000000000 * 1000000);
assert.ok(tokenSupplyData === ARIOToMARIO(1000000000));
});
});

Expand Down Expand Up @@ -83,11 +83,11 @@ describe('handlers', async () => {
const supplyData = JSON.parse(supplyResult.Messages?.[0]?.Data);

assert.ok(
supplyData.total === 1000000000 * 1000000,
supplyData.total === ARIOToMARIO(1000000000),
'total supply should be 1 billion ARIO but was ' + supplyData.total,
);
assert.ok(
supplyData.circulating === 1000000000 * 1000000 - 50000000000000,
supplyData.circulating === ARIOToMARIO(1000000000) - 50000000000000,
'circulating supply should be 0.95 billion ARIO but was ' +
supplyData.circulating,
);
Expand Down
3 changes: 3 additions & 0 deletions tests/helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const genesisEpochTimestamp = 1719900000000; // Tuesday, July 2, 2024, 06
export const epochLength = 1000 * 60 * 60 * 24; // 24 hours
export const distributionDelay = 1000 * 60 * 40; // 40 minutes

export const mARIOPerARIO = 1_000_000;
export const ARIOToMARIO = (amount) => amount * mARIOPerARIO;

const { handle: originalHandle, memory } = await createAosLoader();
export const startMemory = memory;

Expand Down
4 changes: 2 additions & 2 deletions tests/invariants.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'node:assert';
import { getBalances, getVaults, handle } from './helpers.mjs';
import { ARIOToMARIO, getBalances, getVaults, handle } from './helpers.mjs';

function assertValidBalance(balance, expectedMin = 1) {
assert(
Expand Down Expand Up @@ -85,7 +85,7 @@ async function assertNoTotalSupplyInvariants({ timestamp, memory }) {
const supplyData = JSON.parse(supplyResult.Messages?.[0]?.Data);

assert.ok(
supplyData.total === 1000000000 * 1000000,
supplyData.total === ARIOToMARIO(1000000000),
'total supply should be 1,000,000,000,000,000 mARIO but was ' +
supplyData.total,
);
Expand Down
13 changes: 4 additions & 9 deletions tests/monitor/monitor.test.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import {
AOProcess,
ARIO,
ARIO_DEVNET_PROCESS_ID,
ARIO_TESTNET_PROCESS_ID,
Logger,
} from '@ar.io/sdk';
import { AOProcess, ARIO, ARIO_DEVNET_PROCESS_ID, Logger } from '@ar.io/sdk';
import { connect } from '@permaweb/aoconnect';
import { strict as assert } from 'node:assert';
import { describe, it, before, after } from 'node:test';
import { DockerComposeEnvironment, Wait } from 'testcontainers';
import { ARIOToMARIO } from '../helpers.mjs';

// set debug level logs for to get detailed messages
Logger.default.setLogLevel('info');
Expand Down Expand Up @@ -144,7 +139,7 @@ describe('setup', () => {
it('should always be 1 billion ARIO', async () => {
const supplyData = await io.getTokenSupply();
assert(
supplyData.total === 1000000000 * 1000000,
supplyData.total === ARIOToMARIO(1000000000),
`Total supply is not 1 billion ARIO: ${supplyData.total}`,
);
assert(
Expand Down Expand Up @@ -230,7 +225,7 @@ describe('setup', () => {
supplyData.protocolBalance;
assert(
supplyData.total === computedTotal &&
computedTotal === 1000000000 * 1000000,
computedTotal === ARIOToMARIO(1000000000),
`Computed total supply (${computedTotal}) is not equal to the sum of protocol balance, circulating, locked, staked, and delegated and withdrawn provided by the contract (${supplyData.total}) and does not match the expected total of 1 billion ARIO`,
);

Expand Down
Loading