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

PE-7271: update to use ar.io/sdk v3.0.0 and set default CU url to cu.ardrive.io #124

Merged
merged 1 commit into from
Dec 12, 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 .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
VITE_SENTRY_DSN_PROJECT_URI: ${{ secrets.SENTRY_DSN_PROJECT_URI }}
VITE_SENTRY_DSN_PROJECT_ID: ${{ secrets.SENTRY_DSN_PROJECT_ID }}
VITE_GITHUB_HASH: ${{ github.sha }}
VITE_IO_PROCESS_ID: ${{ secrets.IO_PROCESS_ID }}
VITE_ARIO_PROCESS_ID: ${{ vars.ARIO_PROCESS_ID }}
# ao infra settings
VITE_AO_CU_URL: ${{ vars.VITE_AO_CU_URL }}
- name: Add CNAME Record
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
VITE_SENTRY_DSN_PROJECT_URI: ${{ secrets.SENTRY_DSN_PROJECT_URI }}
VITE_SENTRY_DSN_PROJECT_ID: ${{ secrets.SENTRY_DSN_PROJECT_ID }}
VITE_GITHUB_HASH: ${{ github.sha }}
VITE_IO_PROCESS_ID: ${{ secrets.IO_PROCESS_ID }}
VITE_ARIO_PROCESS_ID: ${{ secrets.ARIO_PROCESS_ID }}
VITE_AO_CU_URL: ${{ vars.VITE_AO_CU_URL }}

# Disribute to Firebase
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
VITE_SENTRY_DSN_PROJECT_URI: ${{ secrets.SENTRY_DSN_PROJECT_URI }}
VITE_SENTRY_DSN_PROJECT_ID: ${{ secrets.SENTRY_DSN_PROJECT_ID }}
VITE_GITHUB_HASH: ${{ github.sha }}
VITE_IO_PROCESS_ID: ${{ secrets.IO_PROCESS_ID }}
VITE_ARIO_PROCESS_ID: ${{ vars.ARIO_PROCESS_ID }}
DEPLOY_ANT_PROCESS_ID: ${{ secrets.DEPLOY_ANT_PROCESS_ID }}
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
VITE_AO_CU_URL: ${{ vars.VITE_AO_CU_URL }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"deploy": "yarn build && permaweb-deploy --ant-process ${DEPLOY_ANT_PROCESS_ID}"
},
"dependencies": {
"@ar.io/sdk": "2.7.0-alpha.5",
"@ar.io/sdk": "3.0.0",
"@fontsource/rubik": "^5.0.19",
"@headlessui/react": "^2.2.0",
"@radix-ui/react-tooltip": "^1.0.7",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mIOToken } from '@ar.io/sdk/web';
import { mARIOToken } from '@ar.io/sdk/web';
import { NBSP } from '@src/constants';
import useEpochCountdown from '@src/hooks/useEpochCountdown';
import useGateways from '@src/hooks/useGateways';
Expand Down Expand Up @@ -88,7 +88,7 @@ const Header = () => {
value={
protocolBalance ? (
<div>
{formatWithCommas(new mIOToken(protocolBalance).toIO().valueOf())}{' '}
{formatWithCommas(new mARIOToken(protocolBalance).toARIO().valueOf())}{' '}
{ticker}
</div>
) : undefined
Expand Down
8 changes: 4 additions & 4 deletions src/components/WalletProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AOProcess, IO } from '@ar.io/sdk/web';
import { AOProcess, ARIO } from '@ar.io/sdk/web';
import { connect } from '@permaweb/aoconnect';
import { AO_CU_URL, IO_PROCESS_ID } from '@src/constants';
import { AO_CU_URL, ARIO_PROCESS_ID } from '@src/constants';
import { useEffectOnce } from '@src/hooks/useEffectOnce';
import { ArConnectWalletConnector } from '@src/services/wallets/ArConnectWalletConnector';
import { useGlobalState } from '@src/store';
Expand Down Expand Up @@ -39,10 +39,10 @@ const WalletProvider = ({ children }: { children: ReactElement }) => {
const signer = wallet.signer;

if (signer) {
const writeable = IO.init({
const writeable = ARIO.init({
signer,
process: new AOProcess({
processId: IO_PROCESS_ID.toString(),
processId: ARIO_PROCESS_ID.toString(),
ao: connect({
CU_URL: AO_CU_URL,
}),
Expand Down
8 changes: 4 additions & 4 deletions src/components/modals/InstantWithdrawalModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AoGateway, AoVaultData, mIOToken } from '@ar.io/sdk/web';
import { AoGateway, AoVaultData, mARIOToken } from '@ar.io/sdk/web';
import { WRITE_OPTIONS } from '@src/constants';
import { useGlobalState } from '@src/store';
import { formatAddress, formatDateTime, formatWithCommas } from '@src/utils';
Expand Down Expand Up @@ -54,8 +54,8 @@ const InstantWithdrawalModal = ({

setCalculatedFeeAndAmountReturning({
penaltyRate,
fee: new mIOToken(fee).toIO().valueOf(),
amountReturning: new mIOToken(amountReturning).toIO().valueOf(),
fee: new mARIOToken(fee).toARIO().valueOf(),
amountReturning: new mARIOToken(amountReturning).toARIO().valueOf(),
});
}, [setCalculatedFeeAndAmountReturning, vault]);

Expand Down Expand Up @@ -149,7 +149,7 @@ const InstantWithdrawalModal = ({
<div className="mt-4 flex flex-col gap-1 px-8 pb-4">
<LabelValueRow
label="Stake Withdrawing:"
value={`${formatWithCommas(new mIOToken(vault.balance).toIO().valueOf())} ${ticker}`}
value={`${formatWithCommas(new mARIOToken(vault.balance).toARIO().valueOf())} ${ticker}`}
/>

<LabelValueRow
Expand Down
14 changes: 7 additions & 7 deletions src/components/modals/OperatorStakingModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AoGatewayWithAddress, IOToken, mIOToken } from '@ar.io/sdk/web';
import { AoGatewayWithAddress, ARIOToken, mARIOToken } from '@ar.io/sdk/web';
import { Label, Radio, RadioGroup } from '@headlessui/react';
import { EAY_TOOLTIP_FORMULA, EAY_TOOLTIP_TEXT } from '@src/constants';
import useBalances from '@src/hooks/useBalances';
Expand All @@ -15,7 +15,7 @@ import LabelValueRow from '../LabelValueRow';
import Tooltip from '../Tooltip';
import ErrorMessageIcon from '../forms/ErrorMessageIcon';
import {
validateIOAmount,
validateIOAmount as validateARIOAmount,
validateOperatorWithdrawAmount,
} from '../forms/validation';
import { CircleCheckIcon, CircleIcon, InfoIcon } from '../icons';
Expand Down Expand Up @@ -55,7 +55,7 @@ const OperatorStakingModal = ({
if (!gateway) {
return;
}
setCurrentStake(new mIOToken(gateway.operatorStake).toIO().valueOf());
setCurrentStake(new mARIOToken(gateway.operatorStake).toARIO().valueOf());
}, [gateway]);

const newTotalStake =
Expand All @@ -64,7 +64,7 @@ const OperatorStakingModal = ({
: currentStake - parseFloat(amountToWithdraw);

const minDelegatedStake = gateway
? new mIOToken(gateway?.settings.minDelegatedStake).toIO().valueOf()
? new mARIOToken(gateway?.settings.minDelegatedStake).toARIO().valueOf()
: 10;
const minRequiredStakeToAdd = currentStake > 0 ? 1 : minDelegatedStake;

Expand All @@ -79,7 +79,7 @@ const OperatorStakingModal = ({
).toFixed(4);

const validators = useMemo(() => ({
stakeAmount: validateIOAmount('Stake Amount', ticker, 1, balances?.io),
stakeAmount: validateARIOAmount('Stake Amount', ticker, 1, balances?.io),
withdrawAmount: validateOperatorWithdrawAmount(
'Withdraw Amount',
ticker,
Expand All @@ -99,10 +99,10 @@ const OperatorStakingModal = ({
if (tab == 0 && protocolBalance && gateways && gateway && isFormValid()) {
const newTotalStake = currentStake + parseFloat(amountToStake)
const { EAY } = calculateOperatorRewards(
new mIOToken(protocolBalance).toIO(),
new mARIOToken(protocolBalance).toARIO(),
Object.values(gateways).filter((g) => g.status == 'joined').length,
gateway,
new IOToken(newTotalStake),
new ARIOToken(newTotalStake),
);
setEAY(formatPercentage(EAY));
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/components/modals/ReviewStakeModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AoGatewayWithAddress, IOToken } from '@ar.io/sdk/web';
import { AoGatewayWithAddress, ARIOToken } from '@ar.io/sdk/web';
import { log, WRITE_OPTIONS } from '@src/constants';
import { useGlobalState } from '@src/store';
import { formatAddress, formatWithCommas } from '@src/utils';
Expand Down Expand Up @@ -46,7 +46,7 @@ const ReviewStakeModal = ({
if(gateway.gatewayAddress === walletAddress.toString()) {
const { id: txID } = await arIOWriteableSDK.increaseOperatorStake(
{
increaseQty: new IOToken(amountToStake).toMIO(),
increaseQty: new ARIOToken(amountToStake).toMARIO(),
},
WRITE_OPTIONS,
);
Expand All @@ -58,7 +58,7 @@ const ReviewStakeModal = ({
const { id: txID } = await arIOWriteableSDK.delegateStake(
{
target: gateway.gatewayAddress,
stakeQty: new IOToken(amountToStake).toMIO(),
stakeQty: new ARIOToken(amountToStake).toMARIO(),
},
WRITE_OPTIONS,
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/modals/ReviewWithdrawalModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AoGatewayWithAddress, IOToken } from '@ar.io/sdk/web';
import { AoGatewayWithAddress, ARIOToken } from '@ar.io/sdk/web';
import { log, WRITE_OPTIONS } from '@src/constants';
import { useGlobalState } from '@src/store';
import { WithdrawalType } from '@src/types';
Expand Down Expand Up @@ -69,7 +69,7 @@ const ReviewWithdrawalModal = ({
if (gateway.gatewayAddress === walletAddress.toString()) {
const { id: txID } = await arIOWriteableSDK.decreaseOperatorStake(
{
decreaseQty: new IOToken(amountToWithdraw).toMIO(),
decreaseQty: new ARIOToken(amountToWithdraw).toMARIO(),
instant,
},
WRITE_OPTIONS,
Expand All @@ -81,7 +81,7 @@ const ReviewWithdrawalModal = ({
const { id: txID } = await arIOWriteableSDK.decreaseDelegateStake(
{
target: gateway.gatewayAddress,
decreaseQty: new IOToken(amountToWithdraw).toMIO(),
decreaseQty: new ARIOToken(amountToWithdraw).toMARIO(),
instant,
},
WRITE_OPTIONS,
Expand Down
6 changes: 3 additions & 3 deletions src/components/modals/StakingModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mIOToken } from '@ar.io/sdk/web';
import { mARIOToken } from '@ar.io/sdk/web';
import { Label, Radio, RadioGroup } from '@headlessui/react';
import { EAY_TOOLTIP_FORMULA, EAY_TOOLTIP_TEXT } from '@src/constants';
import useBalances from '@src/hooks/useBalances';
Expand Down Expand Up @@ -66,7 +66,7 @@ const StakingModal = ({
const stake = delegateStakes.stakes.find(
(stake) => stake.gatewayAddress === gateway.gatewayAddress,
)?.balance;
setCurrentStake(new mIOToken(stake ?? 0).toIO().valueOf());
setCurrentStake(new mARIOToken(stake ?? 0).toARIO().valueOf());
}, [delegateStakes, gateway]);

const allowDelegatedStaking =
Expand All @@ -87,7 +87,7 @@ const StakingModal = ({
: '-';

const minDelegatedStake = gateway
? new mIOToken(gateway?.settings.minDelegatedStake).toIO().valueOf()
? new mARIOToken(gateway?.settings.minDelegatedStake).toARIO().valueOf()
: 10;
const minRequiredStakeToAdd = currentStake > 0 ? 1 : minDelegatedStake;

Expand Down
10 changes: 5 additions & 5 deletions src/components/modals/StartGatewayModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IOToken } from '@ar.io/sdk/web';
import { ARIOToken } from '@ar.io/sdk/web';
import { WRITE_OPTIONS, log } from '@src/constants';
import { useGlobalState } from '@src/store';
import { showErrorToast } from '@src/utils/toast';
Expand Down Expand Up @@ -149,15 +149,15 @@ const StartGatewayModal = ({ onClose }: { onClose: () => void }) => {
delegateRewardShareRatio: allowDelegatedStaking
? parseFloat(String(formState.delegatedStakingShareRatio))
: DEFAULT_DELEGATED_STAKING_REWARD_SHARE_RATIO,
minDelegatedStake: new IOToken(
minDelegatedStake: new ARIOToken(
allowDelegatedStaking
? parseFloat(String(formState.minDelegatedStake))
: DEFAULT_DELEGATED_STAKING,
).toMIO().valueOf(),
).toMARIO().valueOf(),
autoStake: true,
operatorStake: new IOToken(
operatorStake: new ARIOToken(
parseFloat(String(formState.stake)),
).toMIO().valueOf(),
).toMARIO().valueOf(),
};

// UNCOMMENT AND COMMENT OUT JOIN NETWORK FOR DEV WORK
Expand Down
6 changes: 3 additions & 3 deletions src/components/modals/WithdrawAllModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AoGateway, mIOToken } from '@ar.io/sdk/web';
import { AoGateway, mARIOToken } from '@ar.io/sdk/web';
import { WRITE_OPTIONS, log } from '@src/constants';
import { useGlobalState } from '@src/store';
import { showErrorToast } from '@src/utils/toast';
Expand Down Expand Up @@ -108,7 +108,7 @@ const WithdrawAllModal = ({
</a>
</td>
<td className="py-2 text-right text-mid ">
{new mIOToken(stake.delegatedStake).toIO().valueOf()}{' '}
{new mARIOToken(stake.delegatedStake).toARIO().valueOf()}{' '}
{ticker}
</td>
</tr>
Expand All @@ -122,7 +122,7 @@ const WithdrawAllModal = ({
<div className="mt-1 flex text-sm text-mid">
<div className="grow">Total Withdrawal:</div>
<div>
{new mIOToken(totalWithdrawalMIO).toIO().valueOf()} {ticker}
{new mARIOToken(totalWithdrawalMIO).toARIO().valueOf()} {ticker}
</div>
</div>

Expand Down
10 changes: 5 additions & 5 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ioDevnetProcessId } from '@ar.io/sdk/web';
import { arioDevnetProcessId } from '@ar.io/sdk/web';
import * as loglevel from 'loglevel';

import Ar from 'arweave/web/ar';
Expand All @@ -17,13 +17,13 @@ export const WRITE_OPTIONS = {
};

export const ARIO_DOCS_URL = 'https://docs.ar.io';
export const IO_PROCESS_ID = new ArweaveTransactionID(
process.env.VITE_IO_PROCESS_ID ?? ioDevnetProcessId,
export const ARIO_PROCESS_ID = new ArweaveTransactionID(
process.env.VITE_ARIO_PROCESS_ID ?? arioDevnetProcessId,
);
export const AO_CU_URL =
process.env.VITE_AO_CU_URL || 'https://cu.ao-testnet.xyz';
process.env.VITE_AO_CU_URL || 'https://cu.ardrive.io';

export const IO_PROCESS_INFO_URL = `https://www.ao.link/#/entity/${IO_PROCESS_ID.toString()}`;
export const IO_PROCESS_INFO_URL = `https://www.ao.link/#/entity/${ARIO_PROCESS_ID.toString()}`;

export const DEFAULT_ARWEAVE_PROTOCOL =
process.env.VITE_GATEWAY_PROTOCOL ?? 'https';
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useBalances.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mIOToken } from '@ar.io/sdk/web';
import { mARIOToken } from '@ar.io/sdk/web';
import { AR } from '@src/constants';
import { useGlobalState } from '@src/store';
import { ArweaveTransactionID } from '@src/utils/ArweaveTransactionId';
Expand Down Expand Up @@ -26,7 +26,7 @@ const useBalances = (walletAddress?: ArweaveTransactionID) => {
]);

const arBalance = +AR.winstonToAr(winstonBalance);
const ioBalance = new mIOToken(mioBalance).toIO().valueOf();
const ioBalance = new mARIOToken(mioBalance).toARIO().valueOf();

return { ar: arBalance, io: ioBalance };
},
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useGatewayInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mIOToken } from '@ar.io/sdk/web';
import { mARIOToken } from '@ar.io/sdk/web';
import { useGlobalState } from '@src/store';
import { formatDateTime, formatWalletAddress, formatWithCommas } from '@src/utils';
import useGateway from './useGateway';
Expand Down Expand Up @@ -29,7 +29,7 @@ export const useGatewayInfo = () => {
['Joined at', formatDateTime(new Date(gateway.startTimestamp))],
[
`Stake (${ticker})`,
formatWithCommas(new mIOToken(gateway.operatorStake).toIO().valueOf()),
formatWithCommas(new mARIOToken(gateway.operatorStake).toARIO().valueOf()),
],
['Status', gateway.status],
['Reward Ratio', gateway.settings.delegateRewardShareRatio],
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useGateways.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AoGateway, AoIORead } from '@ar.io/sdk/web';
import { AoGateway, AoARIORead } from '@ar.io/sdk/web';
import { useGlobalState } from '@src/store';
import { useQuery } from '@tanstack/react-query';

const useGateways = () => {
const arIOReadSDK = useGlobalState((state) => state.arIOReadSDK);

const fetchAllGateways = async (
arIOReadSDK: AoIORead,
arIOReadSDK: AoARIORead,
): Promise<Record<string, AoGateway>> => {
let cursor: string | undefined;
const gateways: Record<string, AoGateway> = {};
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useOperatorRewards.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AoGateway, mIOToken } from '@ar.io/sdk/web';
import { AoGateway, mARIOToken } from '@ar.io/sdk/web';
import { OperatorRewards, calculateOperatorRewards } from '@src/utils/rewards';
import { useEffect, useState } from 'react';
import useGateways from './useGateways';
Expand All @@ -16,10 +16,10 @@ const useOperatorRewards = (gateway: AoGateway | undefined) => {
(g) => g.status == 'joined',
).length;
const operatorRewards = calculateOperatorRewards(
new mIOToken(protocolBalance).toIO(),
new mARIOToken(protocolBalance).toARIO(),
numGateways,
gateway,
new mIOToken(gateway.operatorStake).toIO(),
new mARIOToken(gateway.operatorStake).toARIO(),
);
setOperatorRewards(operatorRewards);
}
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useProtocolBalance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IO_PROCESS_ID } from '@src/constants';
import { ARIO_PROCESS_ID } from '@src/constants';
import { useGlobalState } from '@src/store';
import { useQuery } from '@tanstack/react-query';

Expand All @@ -10,7 +10,7 @@ const useProtocolBalance = () => {
queryFn: () => {
if (arIOReadSDK) {
return arIOReadSDK.getBalance({
address: IO_PROCESS_ID.toString(),
address: ARIO_PROCESS_ID.toString(),
});
}
throw new Error('Error: ArIO Read SDK is not initialized');
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/useRewardsEarned.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mIOToken } from '@ar.io/sdk/web';
import { mARIOToken } from '@ar.io/sdk/web';
import { useEffect, useState } from 'react';
import useEpochs from './useEpochs';

Expand Down Expand Up @@ -27,9 +27,9 @@ const useRewardsEarned = (walletAddress?: string) => {
}, 0);

setRewardsEarned({
previousEpoch: new mIOToken(previousEpochRewards).toIO().valueOf(),
totalForPastAvailableEpochs: new mIOToken(totalForPastAvailableEpochs)
.toIO()
previousEpoch: new mARIOToken(previousEpochRewards).toARIO().valueOf(),
totalForPastAvailableEpochs: new mARIOToken(totalForPastAvailableEpochs)
.toARIO()
.valueOf(),
});
}
Expand Down
Loading
Loading