Skip to content

Commit

Permalink
Implement USDT support
Browse files Browse the repository at this point in the history
  • Loading branch information
tifrel committed May 8, 2023
1 parent ce3daa3 commit ed1f47d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
7 changes: 5 additions & 2 deletions packages/data/src/graphql/fetch.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GRAPHQL_ENDPOINTS, RPC_ENDPOINTS, USDC_ADDRESS } from '@mintbase-js/sdk';
import { GRAPHQL_ENDPOINTS, RPC_ENDPOINTS, USDC_ADDRESS, USDT_ADDRESS } from '@mintbase-js/sdk';
import { GraphQLClient, gql } from 'graphql-request';
import { fetchGraphQl } from './fetch';
import { mbjs } from '@mintbase-js/sdk';
Expand Down Expand Up @@ -52,7 +52,10 @@ describe('graphql/fetch', () => {
graphqlUrl: GRAPHQL_ENDPOINTS['testnet'],
nearRpcUrl: RPC_ENDPOINTS['testnet'],
contractAddress: 'bbb',
ftAddresses: { usdc: USDC_ADDRESS['testnet'] },
ftAddresses: {
usdc: USDC_ADDRESS['testnet'],
usdt: USDT_ADDRESS['testnet'],
},
},

(GraphQLClient as jest.Mock).mockImplementationOnce(() => ({
Expand Down
7 changes: 3 additions & 4 deletions packages/sdk/src/config/config.mocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GRAPHQL_ENDPOINTS, MARKET_CONTRACT_ADDRESS, MINTBASE_CONTRACTS, NEAR_NETWORKS, RPC_ENDPOINTS, USDC_ADDRESS } from '../types';
import { GRAPHQL_ENDPOINTS, MARKET_CONTRACT_ADDRESS, MINTBASE_CONTRACTS, NEAR_NETWORKS, RPC_ENDPOINTS, USDC_ADDRESS, USDT_ADDRESS } from '../types';

export const TESTNET_MOCK = {
apiKey: process.env.MINTBASE_API_KEY,
Expand All @@ -12,7 +12,7 @@ export const TESTNET_MOCK = {
nearRpcUrl: RPC_ENDPOINTS.testnet,
network: NEAR_NETWORKS.TESTNET,
connectProxyAddress: null,
ftAddresses: { usdc: USDC_ADDRESS.testnet },
ftAddresses: { usdc: USDC_ADDRESS.testnet, usdt: USDT_ADDRESS.testnet },
};


Expand All @@ -28,6 +28,5 @@ export const MAINNET_MOCK = {
nearRpcUrl: RPC_ENDPOINTS.mainnet,
network: NEAR_NETWORKS.MAINNET,
connectProxyAddress: null,
ftAddresses: { usdc: USDC_ADDRESS.mainnet },
ftAddresses: { usdc: USDC_ADDRESS.mainnet, usdt: USDT_ADDRESS.mainnet },
};

4 changes: 3 additions & 1 deletion packages/sdk/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BN from 'bn.js';
import { constants } from 'buffer';
import { FtAddresses, USDC_ADDRESS } from './types';
import { FtAddresses, USDC_ADDRESS, USDT_ADDRESS } from './types';

export const GAS = '200000000000000';
export const MAX_GAS = '300000000000000';
Expand Down Expand Up @@ -48,8 +48,10 @@ export const GAS_FOR_TRANSFER = GAS;
export const FT_ADDRESSES: { testnet: FtAddresses; mainnet: FtAddresses } = {
testnet: {
usdc: USDC_ADDRESS.testnet,
usdt: USDT_ADDRESS.testnet,
},
mainnet: {
usdc: USDC_ADDRESS.mainnet,
usdt: USDT_ADDRESS.mainnet,
},
};
29 changes: 29 additions & 0 deletions packages/sdk/src/list/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,32 @@ test('list a token for USDC', () => {
gas: GAS,
});
});

test('list a token for USDT', () => {
const contractAddress = 'contract';
const tokenId = 'token';
const marketAddress = 'account';
const price = '1';
const args = list({
contractAddress: contractAddress,
tokenId: tokenId,
marketAddress: marketAddress,
price: price,
ft: FungibleToken.USDT,
});

expect(args).toEqual({
contractAddress: contractAddress,
methodName: MARKET_METHOD_NAMES.LIST,
args: {
token_id: tokenId,
account_id: marketAddress,
msg: JSON.stringify({
price: price,
ft_contract: mbjs.keys.ftAddresses[FungibleToken.USDT],
}),
},
deposit: LISTING_DEPOSIT,
gas: GAS,
});
});
7 changes: 7 additions & 0 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,20 @@ export enum USDC_ADDRESS {
testnet = 'usdc.fakes.testnet',
}

export enum USDT_ADDRESS {
mainnet = 'dac17f958d2ee523a2206206994597c13d831ec7.factory.bridge.near',
testnet = 'usdt.fakes.testnet',
}

export enum FungibleToken {
USDC = 'usdc',
USDT = 'usdt',
}

// keys here need to be the values of the fungible token enum
export type FtAddresses = {
usdc: USDC_ADDRESS;
usdt: USDT_ADDRESS;
}

export type ConfigOptions = {
Expand Down

0 comments on commit ed1f47d

Please sign in to comment.