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

Commit

Permalink
Merge pull request #245 from ar-io/mIO-writes
Browse files Browse the repository at this point in the history
fix(mIO): modify all writes to accept ONLY mIO and update tools to use SDK
  • Loading branch information
dtfiedler authored May 22, 2024
2 parents bbef928 + af3a72e commit 7abca96
Show file tree
Hide file tree
Showing 47 changed files with 463 additions and 1,323 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
"update-gateway-settings": "yarn ts-node ./tools/cli/update-gateway-settings.ts",
"get-balance": "yarn ts-node ./tools/cli/get-balance.ts",
"increase-operator-stake": "yarn ts-node ./tools/cli/increase-operator-stake.ts",
"create-reserved-name": "yarn ts-node ./tools/cli/reserved-name.ts"
"create-reserved-name": "yarn ts-node ./tools/cli/reserved-name.ts",
"transfer": "yarn ts-node ./tools/cli/transfer.ts"
},
"devDependencies": {
"@ar.io/sdk": "^1.0.0-alpha.12",
"@ar.io/sdk": "1.0.7-alpha.3",
"@commitlint/config-conventional": "^17.7.0",
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
"@types/jest": "^27.4.0",
Expand Down
6 changes: 3 additions & 3 deletions src/actions/write/createVault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('createVault', () => {
const error = await createVault(initialState, {
caller: 'test',
input: {
qty: 100,
qty: new IOToken(100).toMIO().valueOf(),
lockLength: badLockLength,
},
}).catch((e) => e);
Expand All @@ -66,7 +66,7 @@ describe('createVault', () => {
const error = await createVault(initialState, {
caller: 'test',
input: {
qty: 100,
qty: new IOToken(100).toMIO().valueOf(),
lockLength: MIN_TOKEN_LOCK_BLOCK_LENGTH,
},
}).catch((e) => e);
Expand All @@ -86,7 +86,7 @@ describe('createVault', () => {
const { state } = await createVault(initialState, {
caller: 'test',
input: {
qty: 100,
qty: new IOToken(100).toMIO().valueOf(),
lockLength: MIN_TOKEN_LOCK_BLOCK_LENGTH,
},
});
Expand Down
3 changes: 1 addition & 2 deletions src/actions/write/createVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
BlockHeight,
ContractWriteResult,
IOState,
IOToken,
PstAction,
mIOToken,
} from '../../types';
Expand All @@ -22,7 +21,7 @@ export class CreateVault {
);
}
const { qty, lockLength } = input;
this.qty = new IOToken(qty).toMIO();
this.qty = new mIOToken(qty);
this.lockLength = new BlockHeight(lockLength);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/actions/write/decreaseOperatorStake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('decreaseOperatorStake', () => {
[stubbedArweaveTxId]: stubbedGatewayData,
},
balances: {
[stubbedArweaveTxId]: 10000,
[stubbedArweaveTxId]: new IOToken(10000).toMIO().valueOf(),
},
};
const error = await decreaseOperatorStake(initialState, {
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('decreaseOperatorStake', () => {
expect(error).toBeInstanceOf(Error);
expect(error.message).toEqual(
expect.stringContaining(
`Resulting stake is not enough maintain the minimum operator stake of ${MIN_OPERATOR_STAKE.toIO().valueOf()} IO`,
`Resulting stake is not enough maintain the minimum operator stake of ${MIN_OPERATOR_STAKE.valueOf()} mIO`,
),
);
});
Expand All @@ -70,7 +70,7 @@ describe('decreaseOperatorStake', () => {
const error = await decreaseOperatorStake(initialState, {
caller: stubbedArweaveTxId,
input: {
qty: 100,
qty: new IOToken(100).toMIO().valueOf(),
},
}).catch((e: any) => e);
expect(error).toBeInstanceOf(Error);
Expand All @@ -92,7 +92,7 @@ describe('decreaseOperatorStake', () => {
const error = await decreaseOperatorStake(initialState, {
caller: stubbedArweaveTxId,
input: {
qty: 100,
qty: new IOToken(100).toMIO().valueOf(),
},
}).catch((e: any) => e);
expect(error).toBeInstanceOf(Error);
Expand All @@ -118,7 +118,7 @@ describe('decreaseOperatorStake', () => {
const { state } = await decreaseOperatorStake(initialState, {
caller: stubbedArweaveTxId,
input: {
qty: new IOToken(100).valueOf(),
qty: new IOToken(100).toMIO().valueOf(),
},
});
expect(state.gateways[stubbedArweaveTxId]).toEqual({
Expand Down
5 changes: 2 additions & 3 deletions src/actions/write/decreaseOperatorStake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
ContractWriteResult,
Gateway,
IOState,
IOToken,
PstAction,
mIOToken,
} from '../../types';
Expand All @@ -30,7 +29,7 @@ export class DecreaseOperatorStake {
);
}
const { qty } = input;
this.qty = new IOToken(qty).toMIO();
this.qty = new mIOToken(qty);
}
}

Expand All @@ -57,7 +56,7 @@ export const decreaseOperatorStake = async (

if (qty.isGreaterThan(maxWithdraw)) {
throw new ContractError(
`Resulting stake is not enough maintain the minimum operator stake of ${MIN_OPERATOR_STAKE.toIO().valueOf()} IO`,
`Resulting stake is not enough maintain the minimum operator stake of ${MIN_OPERATOR_STAKE.valueOf()} mIO`,
);
}

Expand Down
11 changes: 6 additions & 5 deletions src/actions/write/delegateStake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('delegateStake', () => {
const error = await delegateStake(initialState, {
caller: 'test',
input: {
qty: new IOToken(100).valueOf(),
qty: new IOToken(100).toMIO().valueOf(),
target: stubbedArweaveTxId,
},
}).catch((e) => e);
Expand All @@ -93,7 +93,7 @@ describe('delegateStake', () => {
const error = await delegateStake(initialState, {
caller: 'test',
input: {
qty: new IOToken(100).valueOf(),
qty: new IOToken(100).toMIO().valueOf(),
target: stubbedArweaveTxId,
},
}).catch((e) => e);
Expand All @@ -118,13 +118,14 @@ describe('delegateStake', () => {
},
},
balances: {
test: MIN_DELEGATED_STAKE.valueOf() + 1000,
test:
MIN_DELEGATED_STAKE.valueOf() + new IOToken(1000).toMIO().valueOf(),
},
};
const { state } = await delegateStake(initialState, {
caller: 'test',
input: {
qty: MIN_DELEGATED_STAKE.toIO().valueOf(),
qty: MIN_DELEGATED_STAKE.valueOf(),
target: stubbedArweaveTxId,
},
});
Expand All @@ -148,7 +149,7 @@ describe('delegateStake', () => {
},
},
balances: {
test: 1000,
test: new IOToken(1000).toMIO().valueOf(),
},
});
});
Expand Down
3 changes: 1 addition & 2 deletions src/actions/write/delegateStake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
BlockHeight,
ContractWriteResult,
IOState,
IOToken,
PstAction,
mIOToken,
} from '../../types';
Expand All @@ -22,7 +21,7 @@ export class DelegateStake {
}
const { target, qty } = input;
this.target = target;
this.qty = new IOToken(qty).toMIO();
this.qty = new mIOToken(qty);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/actions/write/extendVault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
MIN_TOKEN_LOCK_BLOCK_LENGTH,
} from '../../constants';
import { getBaselineState, stubbedArweaveTxId } from '../../tests/stubs';
import { IOState } from '../../types';
import { IOState, IOToken } from '../../types';
import { extendVault } from './extendVault';

describe('extendVault', () => {
Expand All @@ -18,7 +18,7 @@ describe('extendVault', () => {
vaults: {
test: {
[stubbedArweaveTxId]: {
balance: 100,
balance: new IOToken(100).toMIO().valueOf(),
end: SmartWeave.block.height + MIN_TOKEN_LOCK_BLOCK_LENGTH,
start: SmartWeave.block.height,
},
Expand Down Expand Up @@ -58,12 +58,12 @@ describe('extendVault', () => {
const initialState: IOState = {
...getBaselineState(),
balances: {
test: 99,
test: new IOToken(99).toMIO().valueOf(),
},
vaults: {
test: {
[stubbedArweaveTxId]: {
balance: 100,
balance: new IOToken(100).toMIO().valueOf(),
end: SmartWeave.block.height + MIN_TOKEN_LOCK_BLOCK_LENGTH,
start: SmartWeave.block.height,
},
Expand All @@ -89,7 +89,7 @@ describe('extendVault', () => {
vaults: {
test: {
[stubbedArweaveTxId]: {
balance: 100,
balance: new IOToken(100).toMIO().valueOf(),
end: SmartWeave.block.height + MIN_TOKEN_LOCK_BLOCK_LENGTH,
start: SmartWeave.block.height,
},
Expand All @@ -110,7 +110,7 @@ describe('extendVault', () => {
vaults: {
test: {
[stubbedArweaveTxId]: {
balance: 100,
balance: new IOToken(100).toMIO().valueOf(),
end:
SmartWeave.block.height +
MIN_TOKEN_LOCK_BLOCK_LENGTH +
Expand Down
10 changes: 5 additions & 5 deletions src/actions/write/increaseOperatorStake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ describe('increaseOperatorStake', () => {
[stubbedArweaveTxId]: stubbedGatewayData,
},
balances: {
[stubbedArweaveTxId]: 100,
[stubbedArweaveTxId]: new IOToken(100).toMIO().valueOf(),
},
};
const error = await increaseOperatorStake(initialState, {
caller: stubbedArweaveTxId,
input: {
qty: 101,
qty: new IOToken(101).toMIO().valueOf(),
},
}).catch((e: any) => e);
expect(error).toBeInstanceOf(Error);
Expand All @@ -67,7 +67,7 @@ describe('increaseOperatorStake', () => {
const error = await increaseOperatorStake(initialState, {
caller: stubbedArweaveTxId,
input: {
qty: 100,
qty: new IOToken(100).toMIO().valueOf(),
},
}).catch((e: any) => e);
expect(error).toBeInstanceOf(Error);
Expand All @@ -89,7 +89,7 @@ describe('increaseOperatorStake', () => {
const error = await increaseOperatorStake(initialState, {
caller: stubbedArweaveTxId,
input: {
qty: 100,
qty: new IOToken(100).toMIO().valueOf(),
},
}).catch((e: any) => e);
expect(error).toBeInstanceOf(Error);
Expand All @@ -116,7 +116,7 @@ describe('increaseOperatorStake', () => {
const { state } = await increaseOperatorStake(initialState, {
caller: stubbedArweaveTxId,
input: {
qty: new IOToken(1000).valueOf(),
qty: new IOToken(1000).toMIO().valueOf(),
},
});
expect(state.gateways[stubbedArweaveTxId]).toEqual({
Expand Down
4 changes: 2 additions & 2 deletions src/actions/write/increaseOperatorStake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
INVALID_INPUT_MESSAGE,
NETWORK_LEAVING_STATUS,
} from '../../constants';
import { ContractWriteResult, IOState, IOToken, PstAction } from '../../types';
import { ContractWriteResult, IOState, PstAction, mIOToken } from '../../types';
import {
unsafeDecrementBalance,
walletHasSufficientBalance,
Expand All @@ -21,7 +21,7 @@ export const increaseOperatorStake = async (
throw new ContractError(INVALID_INPUT_MESSAGE);
}

const qty = new IOToken(input.qty).toMIO();
const qty = new mIOToken(input.qty);

if (!(caller in gateways)) {
throw new ContractError(INVALID_GATEWAY_EXISTS_MESSAGE);
Expand Down
6 changes: 3 additions & 3 deletions src/actions/write/increaseVault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('increaseVault', () => {
caller: 'test',
input: {
id: stubbedArweaveTxId,
qty: new IOToken(50).valueOf(),
qty: new IOToken(50).toMIO().valueOf(),
},
}).catch((e) => e);
expect(error).toBeInstanceOf(Error);
Expand All @@ -75,7 +75,7 @@ describe('increaseVault', () => {
caller: 'test',
input: {
id: stubbedArweaveTxId,
qty: new IOToken(100).valueOf(),
qty: new IOToken(100).toMIO().valueOf(),
},
}).catch((e) => e);
expect(error).toBeInstanceOf(Error);
Expand All @@ -102,7 +102,7 @@ describe('increaseVault', () => {
caller: 'test',
input: {
id: stubbedArweaveTxId,
qty: new IOToken(50).valueOf(),
qty: new IOToken(50).toMIO().valueOf(),
},
});
expect(state).toEqual({
Expand Down
3 changes: 1 addition & 2 deletions src/actions/write/increaseVault.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
ContractWriteResult,
IOState,
IOToken,
PstAction,
TransactionId,
mIOToken,
Expand All @@ -23,7 +22,7 @@ export class IncreaseVault {
}
const { id, qty } = input;
this.id = id;
this.qty = new IOToken(qty).toMIO();
this.qty = new mIOToken(qty);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/actions/write/joinNetwork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const validInput = {
fqdn: 'test.com',
note: 'test-note',
properties: stubbedArweaveTxId,
qty: MIN_OPERATOR_STAKE.toIO().valueOf(),
qty: MIN_OPERATOR_STAKE.valueOf(),
};

describe('joinNetwork', () => {
Expand Down Expand Up @@ -245,7 +245,7 @@ describe('joinNetwork', () => {
fqdn: 'test.com',
note: 'test-note',
properties: stubbedArweaveTxId,
qty: MIN_OPERATOR_STAKE.toIO().valueOf(),
qty: MIN_OPERATOR_STAKE.valueOf(),
};

const initialState = {
Expand Down
3 changes: 1 addition & 2 deletions src/actions/write/joinNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import {
ContractWriteResult,
IOState,
IOToken,
PstAction,
TransactionId,
mIOToken,
Expand Down Expand Up @@ -59,7 +58,7 @@ export class JoinNetwork {
delegateRewardShareRatio = 0,
minDelegatedStake = MIN_DELEGATED_STAKE,
} = input;
this.qty = new IOToken(qty).toMIO();
this.qty = new mIOToken(qty);
this.label = label;
this.port = port;
this.protocol = protocol;
Expand Down
Loading

0 comments on commit 7abca96

Please sign in to comment.