Skip to content

Commit

Permalink
Iota stardust
Browse files Browse the repository at this point in the history
Fixes

Fixes

Fixes

Fixes

Fixes

Fixes

Fixes
  • Loading branch information
Boldizsar Mezei committed Oct 3, 2023
1 parent 3afe9b3 commit bc849ab
Show file tree
Hide file tree
Showing 185 changed files with 2,649 additions and 3,249 deletions.
108 changes: 72 additions & 36 deletions .github/workflows/functions_tangle-online-unit-tests_emulator.yml

Large diffs are not rendered by default.

118 changes: 77 additions & 41 deletions .github/workflows/functions_tangle-unit-tests.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"joi-to-types": "ts-node ./scripts/joi-generator-post.ts && ts-node ./scripts/joi-generator-tangle.ts && npm run prettier"
},
"devDependencies": {
"joi-to-typescript": "^4.4.1"
"joi-to-typescript": "4.7.0"
}
}
6 changes: 3 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
"cors": "^2.8.5",
"dayjs": "^1.11.9",
"express": "^4.18.2",
"joi": "^17.10.1",
"joi": "17.10.2",
"lodash": "^4.17.21",
"rxjs": "^7.8.1",
"ws": "^8.13.0",
"@iota/iota.js-next": "npm:@iota/[email protected]",
"@iota/util.js-next": "npm:@iota/[email protected]"
"@iota/iota.js": "npm:@iota/[email protected]",
"@iota/util.js": "npm:@iota/[email protected]"
},
"devDependencies": {
"@types/express": "^4.17.17",
Expand Down
17 changes: 2 additions & 15 deletions packages/api/src/getTopMilestones.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { build5Db } from '@build-5/database';
import { COL, Network } from '@build-5/interfaces';
import { Network, getMilestoneCol } from '@build-5/interfaces';
import { combineLatest, map } from 'rxjs';
import { queryToObservable } from './common';

Expand All @@ -11,17 +11,4 @@ export const getTopMilestones = async (_: string) => {
};

const networkToQuery = (network: Network) =>
build5Db().collection(getMilestoneColForNetwrok(network)).orderBy('createdOn', 'desc').limit(1);

const getMilestoneColForNetwrok = (network: Network) => {
switch (network) {
case Network.IOTA:
return COL.MILESTONE;
case Network.ATOI:
return COL.MILESTONE_ATOI;
case Network.SMR:
return COL.MILESTONE_SMR;
case Network.RMS:
return COL.MILESTONE_RMS;
}
};
build5Db().collection(getMilestoneCol(network)).orderBy('createdOn', 'desc').limit(1);

This file was deleted.

5 changes: 1 addition & 4 deletions packages/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,8 @@
"@build-5/interfaces": "*",
"@ffmpeg-installer/ffmpeg": "1.1.0",
"@ffprobe-installer/ffprobe": "2.0.0",
"@iota/crypto.js": "1.8.6",
"@iota/crypto.js-next": "npm:@iota/[email protected]",
"@iota/iota.js": "1.8.6",
"@iota/iota.js-next": "npm:@iota/[email protected]",
"@iota/util.js": "1.8.6",
"@iota/util.js-next": "npm:@iota/[email protected]",
"@metamask/eth-sig-util": "5.0.2",
"algoliasearch": "4.16.0",
Expand All @@ -100,7 +97,7 @@
"glob": "9.3.4",
"interfaces": "^0.0.3",
"is-ipfs": "8.0.1",
"joi": "17.10.1",
"joi": "17.10.2",
"js-big-decimal": "1.4.1",
"jsonwebtoken": "9.0.0",
"lodash": "4.17.21",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import { AddressTypes, ED25519_ADDRESS_TYPE, INodeInfo } from '@iota/iota.js-nex
import dayjs from 'dayjs';
import { last } from 'lodash';
import { build5Db, getSnapshot } from '../../firebase/firestore/build5Db';
import { SmrWallet } from '../../services/wallet/SmrWalletService';
import { AddressDetails, WalletService } from '../../services/wallet/wallet';
import { AddressDetails, WalletService } from '../../services/wallet/wallet.service';
import { assertMemberHasValidAddress, assertSpaceHasValidAddress } from '../../utils/address.utils';
import {
EMPTY_NFT_ID,
Expand Down Expand Up @@ -82,7 +81,7 @@ export const mintCollectionOrderControl = async (owner: string, params: Collecti
.get<Space>();
assertSpaceHasValidAddress(royaltySpace, network);

const wallet = (await WalletService.newWallet(network)) as SmrWallet;
const wallet = await WalletService.newWallet(network);
const targetAddress = await wallet.getNewIotaAddressDetails();

const { storageDeposit: nftsStorageDeposit, nftsToMint } = await getNftsTotalStorageDeposit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@build-5/interfaces';
import dayjs from 'dayjs';
import { build5Db } from '../../firebase/firestore/build5Db';
import { WalletService } from '../../services/wallet/wallet';
import { WalletService } from '../../services/wallet/wallet.service';
import { dateToTimestamp } from '../../utils/dateTime.utils';
import { invalidArgument } from '../../utils/error.utils';
import { getRandomEthAddress } from '../../utils/wallet.utils';
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/src/controls/nft/nft.deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@build-5/interfaces';
import dayjs from 'dayjs';
import { build5Db } from '../../firebase/firestore/build5Db';
import { WalletService } from '../../services/wallet/wallet';
import { WalletService } from '../../services/wallet/wallet.service';
import { dateToTimestamp } from '../../utils/dateTime.utils';
import { getRandomEthAddress } from '../../utils/wallet.utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@build-5/interfaces';
import dayjs from 'dayjs';
import { build5Db } from '../../firebase/firestore/build5Db';
import { WalletService } from '../../services/wallet/wallet';
import { WalletService } from '../../services/wallet/wallet.service';
import { generateRandomAmount } from '../../utils/common.utils';
import { dateToTimestamp } from '../../utils/dateTime.utils';
import { invalidArgument } from '../../utils/error.utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import dayjs from 'dayjs';
import { chunk } from 'lodash';
import { build5Db } from '../../firebase/firestore/build5Db';
import { CreateAirdropsRequest } from '../../runtime/firebase/token/base/TokenAirdropRequestSchema';
import { SmrWallet } from '../../services/wallet/SmrWalletService';
import { WalletService } from '../../services/wallet/wallet';
import { WalletService } from '../../services/wallet/wallet.service';
import { packBasicOutput } from '../../utils/basic-output.utils';
import { dateToTimestamp } from '../../utils/dateTime.utils';
import { invalidArgument } from '../../utils/error.utils';
Expand All @@ -44,7 +43,7 @@ export const airdropMintedTokenControl = async (owner: string, params: CreateAir
const drops = params.drops;

const totalDropped = drops.reduce((acc, act) => acc + act.count, 0);
const wallet = (await WalletService.newWallet(token.mintingData?.network)) as SmrWallet;
const wallet = await WalletService.newWallet(token.mintingData?.network);
const targetAddress = await wallet.getNewIotaAddressDetails();
const nativeToken = {
amount: HexHelper.fromBigInt256(bigInt(totalDropped)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import { IndexerPluginClient } from '@iota/iota.js-next';
import dayjs from 'dayjs';
import { isEmpty } from 'lodash';
import { build5Db } from '../../firebase/firestore/build5Db';
import { SmrWallet } from '../../services/wallet/SmrWalletService';
import { WalletService } from '../../services/wallet/wallet';
import { WalletService } from '../../services/wallet/wallet.service';
import { generateRandomAmount } from '../../utils/common.utils';
import { dateToTimestamp } from '../../utils/dateTime.utils';
import { invalidArgument } from '../../utils/error.utils';
Expand All @@ -31,7 +30,7 @@ export const importMintedTokenControl = async (owner: string, params: ImportMint
throw invalidArgument(WenError.token_already_exists_for_space);
}

const wallet = (await WalletService.newWallet(params.network as Network)) as SmrWallet;
const wallet = await WalletService.newWallet(params.network as Network);
const indexer = new IndexerPluginClient(wallet.client);
const foundryResponse = await indexer.foundry(params.tokenId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
import { TransactionHelper } from '@iota/iota.js-next';
import dayjs from 'dayjs';
import { build5Db } from '../../firebase/firestore/build5Db';
import { SmrWallet } from '../../services/wallet/SmrWalletService';
import { AddressDetails, WalletService } from '../../services/wallet/wallet';
import { Wallet } from '../../services/wallet/wallet';
import { AddressDetails, WalletService } from '../../services/wallet/wallet.service';
import { assertMemberHasValidAddress } from '../../utils/address.utils';
import { dateToTimestamp } from '../../utils/dateTime.utils';
import { invalidArgument } from '../../utils/error.utils';
Expand Down Expand Up @@ -52,7 +52,7 @@ export const mintTokenControl = (owner: string, params: TokenMintRequest) =>
const member = await build5Db().doc(`${COL.MEMBER}/${owner}`).get<Member>();
assertMemberHasValidAddress(member, params.network as Network);

const wallet = (await WalletService.newWallet(params.network as Network)) as SmrWallet;
const wallet = await WalletService.newWallet(params.network as Network);
const targetAddress = await wallet.getNewIotaAddressDetails();

const totalDistributed =
Expand Down Expand Up @@ -91,7 +91,7 @@ const getStorageDepositForMinting = async (
token: Token,
totalDistributed: number,
address: AddressDetails,
wallet: SmrWallet,
wallet: Wallet,
) => {
const aliasOutput = createAliasOutput(address, wallet.info);
const metadata = await tokenToFoundryMetadata(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import dayjs from 'dayjs';
import { isEmpty } from 'lodash';
import { build5Db } from '../../firebase/firestore/build5Db';
import { WalletService } from '../../services/wallet/wallet';
import { WalletService } from '../../services/wallet/wallet.service';
import { generateRandomAmount } from '../../utils/common.utils';
import { dateToTimestamp } from '../../utils/dateTime.utils';
import { invalidArgument } from '../../utils/error.utils';
Expand Down
3 changes: 1 addition & 2 deletions packages/functions/src/controls/token/token.credit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
COL,
CreditTokenRequest,
DEFAULT_NETWORK,
Member,
MIN_IOTA_AMOUNT,
Member,
SUB_COL,
Token,
TokenDistribution,
Expand Down Expand Up @@ -34,7 +34,6 @@ export const creditTokenControl = async (
await build5Db().runTransaction(async (transaction) => {
const tokenDocRef = build5Db().doc(`${COL.TOKEN}/${params.token}`);
const distributionDocRef = tokenDocRef.collection(SUB_COL.DISTRIBUTION).doc(owner);

const distribution = await transaction.get<TokenDistribution>(distributionDocRef);
if (!distribution || (distribution.totalDeposit || 0) < params.amount) {
throw invalidArgument(WenError.not_enough_funds);
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/src/controls/token/token.order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import dayjs from 'dayjs';
import { build5Db } from '../../firebase/firestore/build5Db';
import { assertHasAccess } from '../../services/validators/access';
import { WalletService } from '../../services/wallet/wallet';
import { WalletService } from '../../services/wallet/wallet.service';
import { assertMemberHasValidAddress, getAddress } from '../../utils/address.utils';
import { isProdEnv } from '../../utils/config.utils';
import { dateToTimestamp } from '../../utils/dateTime.utils';
Expand Down
4 changes: 1 addition & 3 deletions packages/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ import { collectionWrite } from './triggers/collection.trigger';
import {
atoiMilestoneTransactionWrite,
iotaMilestoneTransactionWrite,
} from './triggers/milestone-transactions-triggers/iota-milestone-transaction.trigger';
import {
rmsMilestoneTransactionWrite,
smrMilestoneTransactionWrite,
} from './triggers/milestone-transactions-triggers/smr-milestone-transaction.trigger';
} from './triggers/milestone-transactions-triggers/milestone-transaction.trigger';
import { mnemonicWrite } from './triggers/mnemonic.trigger';
import { nftWrite } from './triggers/nft.trigger';
import { onProposalUpdated } from './triggers/proposal.trigger';
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/src/services/payment/address-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class AddressService {
const guardians = await spaceDocRef.collection(SUB_COL.GUARDIANS).get<SpaceGuardian>();
const proposal = createUpdateSpaceValidatedAddressProposal(
order,
match.from.address,
match.from,
owner,
space!,
guardians.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { createNftOutput } from '../../../utils/collection-minting-utils/nft.uti
import { getContentType } from '../../../utils/storage.utils';
import { createAliasOutput } from '../../../utils/token-minting-utils/alias.utils';
import { getRandomEthAddress } from '../../../utils/wallet.utils';
import { SmrWallet } from '../../wallet/SmrWalletService';
import { Wallet } from '../../wallet/wallet';
import { TransactionMatch, TransactionService } from '../transaction-service';

export class AwardService {
Expand Down Expand Up @@ -177,7 +177,7 @@ export const awardToIpfsMetadata = (award: Award) => {
return metadata;
};

export const getAwardgStorageDeposits = async (award: Award, token: Token, wallet: SmrWallet) => {
export const getAwardgStorageDeposits = async (award: Award, token: Token, wallet: Wallet) => {
const address = await wallet.getNewIotaAddressDetails();

const aliasOutput = createAliasOutput(address, wallet.info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ import {
} from '../../../utils/nft.output.utils';
import { getRandomEthAddress } from '../../../utils/wallet.utils';
import { NftWallet } from '../../wallet/NftWallet';
import { SmrWallet } from '../../wallet/SmrWalletService';
import { WalletService } from '../../wallet/wallet';
import { WalletService } from '../../wallet/wallet.service';
import { TransactionMatch, TransactionService } from '../transaction-service';
export class NftDepositService {
constructor(readonly transactionService: TransactionService) {}
Expand Down Expand Up @@ -277,7 +276,7 @@ export class NftDepositService {
throw WenError.nft_not_irc27_compilant;
}

const wallet = (await WalletService.newWallet(order.network)) as SmrWallet;
const wallet = await WalletService.newWallet(order.network);
const nftWallet = new NftWallet(wallet);
const collectionOutput = await nftWallet.getById(nftMetadata.collectionId);
const collectionMetadata = getNftOutputMetadata(collectionOutput);
Expand Down
18 changes: 5 additions & 13 deletions packages/functions/src/services/payment/nft/nft-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
MilestoneTransactionEntry,
Nft,
NftAccess,
NftStatus,
Transaction,
TransactionPayloadType,
} from '@build-5/interfaces';
Expand Down Expand Up @@ -116,7 +117,7 @@ export class NftService {

const tanglePuchase = order.payload.tanglePuchase;
const disableWithdraw = order.payload.disableWithdraw;
if (!disableWithdraw && tanglePuchase && AVAILABLE_NETWORKS.includes(order.network!)) {
if (!disableWithdraw && tanglePuchase && nft.status === NftStatus.MINTED) {
await this.withdrawNft(order, nft);
}
} else {
Expand Down Expand Up @@ -240,10 +241,7 @@ export class NftService {
address: previousHighestPay.payload.targetAddress!,
amount: previousHighestPay.payload.amount!,
},
from: {
address: previousHighestPay.payload.sourceAddress!,
amount: previousHighestPay.payload.amount!,
},
from: previousHighestPay.payload.sourceAddress!,
},
dateToTimestamp(dayjs(payment.createdOn?.toDate()).subtract(1, 's')),
sameOwner,
Expand Down Expand Up @@ -330,10 +328,7 @@ export class NftService {
address: paymentPayload.targetAddress!,
amount: paymentPayload.amount!,
},
from: {
address: paymentPayload.sourceAddress!,
amount: paymentPayload.amount!,
},
from: paymentPayload.sourceAddress!,
});
}
}
Expand Down Expand Up @@ -395,10 +390,7 @@ export class NftService {
address: highestPay.payload.targetAddress!,
amount: highestPay.payload.amount!,
},
from: {
address: highestPay.payload.sourceAddress!,
amount: highestPay.payload.amount!,
},
from: highestPay.payload.sourceAddress!,
},
serverTime(),
sameOwner,
Expand Down
Loading

0 comments on commit bc849ab

Please sign in to comment.