Skip to content

Commit

Permalink
Merge branch 'main' of github.com:immutable/ts-immutable-sdk into TD-…
Browse files Browse the repository at this point in the history
…1295-seaport-js-v3
  • Loading branch information
Sam-Jeston committed Mar 21, 2024
2 parents 42569f2 + 4aa9a47 commit f0627b6
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 111 deletions.
12 changes: 6 additions & 6 deletions .github/scripts/update-docs-link.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ fi

# Update versions in the browserBundle docs (https://docs.immutable.com/docs/x/sdks/typescript/#browser-bundle)
FILE=docs/main/sdks/_typescript.mdx
major=$(awk '{
major=$(echo $VERSION | awk '{
split($0, a, ".");
print a[1];
}' <<< $VERSION)
minor=$(awk '{
}')
minor=$(echo $VERSION | awk '{
split($0, a, ".");
print a[2];
}' <<< $VERSION)
patch=$(awk '{
}')
patch=$(echo $VERSION | awk '{
split($0, a, ".");
print a[3];
}' <<< $VERSION)
}')
echo "major: $major minor: $minor patch: $patch"

# On Mac OS, sed requires an empty string as an argument to -i to avoid creating a backup file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,17 @@ export const balanceCheck = async (

// Wait for all balances and calculate the requirements
const promisesResponses = await Promise.all(balancePromises);
const balanceRequirements: BalanceRequirement[] = [];
const erc721BalanceRequirements: BalanceRequirement[] = [];
const tokenBalanceRequirementPromises: Promise<BalanceRequirement>[] = [];

// Get all ERC20 and NATIVE balances
if (requiredToken.length > 0 && promisesResponses.length > 0) {
const result = promisesResponses.shift();
if (result) {
requiredToken.forEach((item) => {
balanceRequirements.push(getTokenBalanceRequirement(item as (NativeItem | ERC20Item), result));
tokenBalanceRequirementPromises.push(
getTokenBalanceRequirement(item as (NativeItem | ERC20Item), result, provider),
);
});
}
}
Expand All @@ -175,10 +178,14 @@ export const balanceCheck = async (
const result = promisesResponses.shift();
if (result) {
requiredERC721.forEach((item) => {
balanceRequirements.push(getERC721BalanceRequirement(item as (ERC721Item), result));
erc721BalanceRequirements.push(getERC721BalanceRequirement(item as (ERC721Item), result));
});
}
}
const balanceRequirements = [
...erc721BalanceRequirements,
...(await Promise.all(tokenBalanceRequirementPromises)),
];

// Find if there are any requirements that aren't sufficient.
// If there is not item with sufficient === false then the requirements
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { BigNumber } from 'ethers';
import { Web3Provider } from '@ethersproject/providers';
import {
ERC20Item, ERC721Item, ItemBalance, ItemRequirement, ItemType, NativeItem,
ChainId,
ERC20Item,
ERC721Item,
ItemBalance,
ItemRequirement,
ItemType,
NativeItem,
} from '../../types';
import {
getERC721BalanceRequirement,
Expand Down Expand Up @@ -63,30 +70,28 @@ describe('balanceRequirement', () => {
},
];
const result = getERC721BalanceRequirement(itemRequirement, balances);
expect(result).toEqual(
{
sufficient: true,
expect(result).toEqual({
sufficient: true,
type: ItemType.ERC721,
delta: {
balance: BigNumber.from(0),
formattedBalance: '0',
},
required: {
type: ItemType.ERC721,
delta: {
balance: BigNumber.from(0),
formattedBalance: '0',
},
required: {
type: ItemType.ERC721,
balance: BigNumber.from(1),
formattedBalance: '1',
contractAddress: '0xERC721',
id: '0',
},
current: {
type: ItemType.ERC721,
balance: BigNumber.from(1),
formattedBalance: '1',
contractAddress: '0xERC721',
id: '0',
},
balance: BigNumber.from(1),
formattedBalance: '1',
contractAddress: '0xERC721',
id: '0',
},
);
current: {
type: ItemType.ERC721,
balance: BigNumber.from(1),
formattedBalance: '1',
contractAddress: '0xERC721',
id: '0',
},
});
});

it('should return sufficient false if does not meet requirement for ERC721', () => {
Expand All @@ -110,35 +115,46 @@ describe('balanceRequirement', () => {
},
];
const result = getERC721BalanceRequirement(itemRequirement, balances);
expect(result).toEqual(
{
sufficient: false,
expect(result).toEqual({
sufficient: false,
type: ItemType.ERC721,
delta: {
balance: BigNumber.from(1),
formattedBalance: '1',
},
required: {
type: ItemType.ERC721,
delta: {
balance: BigNumber.from(1),
formattedBalance: '1',
},
required: {
type: ItemType.ERC721,
balance: BigNumber.from(1),
formattedBalance: '1',
contractAddress: '0xERC721',
id: '0',
},
current: {
type: ItemType.ERC721,
balance: BigNumber.from(0),
formattedBalance: '0',
contractAddress: '0xERC721',
id: '0',
},
balance: BigNumber.from(1),
formattedBalance: '1',
contractAddress: '0xERC721',
id: '0',
},
);
current: {
type: ItemType.ERC721,
balance: BigNumber.from(0),
formattedBalance: '0',
contractAddress: '0xERC721',
id: '0',
},
});
});
});

describe('getTokenBalanceRequirement', () => {
it('should return sufficient true if meets requirements for NATIVE', () => {
let mockProvider: Web3Provider;

beforeEach(() => {
mockProvider = {
getSigner: jest.fn().mockReturnValue({
getAddress: jest.fn().mockResolvedValue('0xADDRESS'),
}),
network: {
chainId: ChainId.ETHEREUM,
},
} as unknown as Web3Provider;
});

it('should return sufficient true if meets requirements for NATIVE', async () => {
const itemRequirement: NativeItem = {
type: ItemType.NATIVE,
amount: BigNumber.from('1000000000000000000'),
Expand All @@ -156,7 +172,11 @@ describe('balanceRequirement', () => {
},
];

const result = getTokenBalanceRequirement(itemRequirement, balances);
const result = await getTokenBalanceRequirement(
itemRequirement,
balances,
mockProvider,
);
expect(result).toEqual({
sufficient: true,
type: ItemType.NATIVE,
Expand Down Expand Up @@ -187,7 +207,7 @@ describe('balanceRequirement', () => {
});
});

it('should return sufficient true if meets requirements for ERC20', () => {
it('should return sufficient true if meets requirements for ERC20', async () => {
const itemRequirement: ERC20Item = {
type: ItemType.ERC20,
tokenAddress: '0xERC20',
Expand All @@ -208,7 +228,11 @@ describe('balanceRequirement', () => {
},
];

const result = getTokenBalanceRequirement(itemRequirement, balances);
const result = await getTokenBalanceRequirement(
itemRequirement,
balances,
mockProvider,
);
expect(result).toEqual({
sufficient: true,
type: ItemType.ERC20,
Expand Down Expand Up @@ -241,7 +265,7 @@ describe('balanceRequirement', () => {
});
});

it('should return sufficient false if requirements not met for NATIVE', () => {
it('should return sufficient false if requirements not met for NATIVE', async () => {
const itemRequirement: NativeItem = {
type: ItemType.NATIVE,
amount: BigNumber.from('1000000000000000000'),
Expand Down Expand Up @@ -270,7 +294,11 @@ describe('balanceRequirement', () => {
},
];

const result = getTokenBalanceRequirement(itemRequirement, balances);
const result = await getTokenBalanceRequirement(
itemRequirement,
balances,
mockProvider,
);
expect(result).toEqual({
sufficient: false,
type: ItemType.NATIVE,
Expand Down Expand Up @@ -301,7 +329,7 @@ describe('balanceRequirement', () => {
});
});

it('should return sufficient false if requirements not met for ERC20', () => {
it('should return sufficient false if requirements not met for ERC20', async () => {
const itemRequirement: ERC20Item = {
type: ItemType.ERC20,
tokenAddress: '0xERC20',
Expand Down Expand Up @@ -332,7 +360,11 @@ describe('balanceRequirement', () => {
},
];

const result = getTokenBalanceRequirement(itemRequirement, balances);
const result = await getTokenBalanceRequirement(
itemRequirement,
balances,
mockProvider,
);
expect(result).toEqual({
sufficient: false,
type: ItemType.ERC20,
Expand Down
Loading

0 comments on commit f0627b6

Please sign in to comment.