diff --git a/README.md b/README.md index 61b66faf..cafd2585 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ console.log(`Faucet transaction: ${faucetTransaction}`); // Create a new Wallet to transfer funds to. // Then, we can transfer 0.00001 ETH out of the Wallet to another Wallet. const anotherWallet = await user.createWallet(); -const transfer = await wallet.createTransfer(0.00001, Coinbase.assetList.Eth, anotherWallet); +const transfer = await wallet.createTransfer(0.00001, Coinbase.assets.Eth, anotherWallet); ``` ### Re-Instantiating Wallets diff --git a/src/coinbase/address.ts b/src/coinbase/address.ts index aeb9fb76..5de1e2e4 100644 --- a/src/coinbase/address.ts +++ b/src/coinbase/address.ts @@ -146,7 +146,7 @@ export class Address { * Transfers the given amount of the given Asset to the given address. Only same-Network Transfers are supported. * * @param amount - The amount of the Asset to send. - * @param assetId - The ID of the Asset to send. For Ether, Coinbase.assetList.Eth, Coinbase.assetList.Gwei, and Coinbase.assetList.Wei supported. + * @param assetId - The ID of the Asset to send. For Ether, Coinbase.assets.Eth, Coinbase.assets.Gwei, and Coinbase.assets.Wei supported. * @param destination - The destination of the transfer. If a Wallet, sends to the Wallet's default address. If a String, interprets it as the address ID. * @param intervalSeconds - The interval at which to poll the Network for Transfer status, in seconds. * @param timeoutSeconds - The maximum amount of time to wait for the Transfer to complete, in seconds. @@ -175,18 +175,18 @@ export class Address { } switch (assetId) { - case Coinbase.assetList.Eth: + case Coinbase.assets.Eth: normalizedAmount = normalizedAmount.mul(WEI_PER_ETHER); break; - case Coinbase.assetList.Gwei: + case Coinbase.assets.Gwei: normalizedAmount = normalizedAmount.mul(WEI_PER_GWEI); break; - case Coinbase.assetList.Wei: + case Coinbase.assets.Wei: break; - case Coinbase.assetList.Weth: + case Coinbase.assets.Weth: normalizedAmount = normalizedAmount.mul(WEI_PER_ETHER); break; - case Coinbase.assetList.Usdc: + case Coinbase.assets.Usdc: normalizedAmount = normalizedAmount.mul(ATOMIC_UNITS_PER_USDC); break; default: @@ -197,9 +197,9 @@ export class Address { const normalizedAssetId = ((): string => { switch (assetId) { - case Coinbase.assetList.Gwei: - case Coinbase.assetList.Wei: - return Coinbase.assetList.Eth; + case Coinbase.assets.Gwei: + case Coinbase.assets.Wei: + return Coinbase.assets.Eth; default: return assetId; } diff --git a/src/coinbase/coinbase.ts b/src/coinbase/coinbase.ts index 9ca680b7..520d73d9 100644 --- a/src/coinbase/coinbase.ts +++ b/src/coinbase/coinbase.ts @@ -34,7 +34,7 @@ export class Coinbase { * * @constant */ - static assetList = { + static assets = { Eth: "eth", Wei: "wei", Gwei: "gwei", diff --git a/src/coinbase/tests/address_test.ts b/src/coinbase/tests/address_test.ts index bed6cce4..372d609f 100644 --- a/src/coinbase/tests/address_test.ts +++ b/src/coinbase/tests/address_test.ts @@ -70,7 +70,7 @@ describe("Address", () => { it("should return the correct list of balances", async () => { const balances = await address.getBalances(); - expect(balances.get(Coinbase.assetList.Eth)).toEqual(new Decimal(1)); + expect(balances.get(Coinbase.assets.Eth)).toEqual(new Decimal(1)); expect(balances.get("usdc")).toEqual(new Decimal(5000)); expect(balances.get("weth")).toEqual(new Decimal(3)); expect(Coinbase.apiClients.address!.listAddressBalances).toHaveBeenCalledWith( @@ -81,13 +81,13 @@ describe("Address", () => { }); it("should return the correct ETH balance", async () => { - const ethBalance = await address.getBalance(Coinbase.assetList.Eth); + const ethBalance = await address.getBalance(Coinbase.assets.Eth); expect(ethBalance).toBeInstanceOf(Decimal); expect(ethBalance).toEqual(new Decimal(1)); expect(Coinbase.apiClients.address!.getAddressBalance).toHaveBeenCalledWith( address.getWalletId(), address.getId(), - Coinbase.assetList.Eth, + Coinbase.assets.Eth, ); expect(Coinbase.apiClients.address!.getAddressBalance).toHaveBeenCalledTimes(1); }); @@ -228,7 +228,7 @@ describe("Address", () => { const transfer = await address.createTransfer( weiAmount, - Coinbase.assetList.Wei, + Coinbase.assets.Wei, destination, intervalSeconds, timeoutSeconds, @@ -245,7 +245,7 @@ describe("Address", () => { await expect( address.createTransfer( weiAmount, - Coinbase.assetList.Wei, + Coinbase.assets.Wei, destination, intervalSeconds, timeoutSeconds, @@ -258,7 +258,7 @@ describe("Address", () => { await expect( addressWithoutKey.createTransfer( weiAmount, - Coinbase.assetList.Wei, + Coinbase.assets.Wei, destination, intervalSeconds, timeoutSeconds, @@ -274,7 +274,7 @@ describe("Address", () => { await expect( address.createTransfer( weiAmount, - Coinbase.assetList.Wei, + Coinbase.assets.Wei, destination, intervalSeconds, timeoutSeconds, @@ -294,7 +294,7 @@ describe("Address", () => { await expect( address.createTransfer( weiAmount, - Coinbase.assetList.Wei, + Coinbase.assets.Wei, destination, intervalSeconds, timeoutSeconds, @@ -307,7 +307,7 @@ describe("Address", () => { await expect( address.createTransfer( insufficientAmount, - Coinbase.assetList.Wei, + Coinbase.assets.Wei, destination, intervalSeconds, timeoutSeconds, diff --git a/src/coinbase/tests/balance_map_test.ts b/src/coinbase/tests/balance_map_test.ts index 53c6c727..45ec0c0b 100644 --- a/src/coinbase/tests/balance_map_test.ts +++ b/src/coinbase/tests/balance_map_test.ts @@ -15,7 +15,7 @@ describe("BalanceMap", () => { describe(".fromBalances", () => { const ethBalanceModel: BalanceModel = { asset: { - asset_id: Coinbase.assetList.Eth, + asset_id: Coinbase.assets.Eth, network_id: Coinbase.networkList.BaseSepolia, }, amount: ethAtomicAmount, @@ -42,14 +42,14 @@ describe("BalanceMap", () => { const balanceMap = BalanceMap.fromBalances(balances); it("returns a new BalanceMap object with the correct balances", () => { - expect(balanceMap.get(Coinbase.assetList.Eth)).toEqual(ethAmount); + expect(balanceMap.get(Coinbase.assets.Eth)).toEqual(ethAmount); expect(balanceMap.get("usdc")).toEqual(usdcAmount); expect(balanceMap.get("weth")).toEqual(wethAmount); }); }); describe(".add", () => { - const assetId = Coinbase.assetList.Eth; + const assetId = Coinbase.assets.Eth; const balance = Balance.fromModelAndAssetId( { amount: ethAtomicAmount, @@ -67,7 +67,7 @@ describe("BalanceMap", () => { }); describe(".toString", () => { - const assetId = Coinbase.assetList.Eth; + const assetId = Coinbase.assets.Eth; const balance = Balance.fromModelAndAssetId( { amount: ethAtomicAmount, diff --git a/src/coinbase/tests/balance_test.ts b/src/coinbase/tests/balance_test.ts index 1230c138..5bb7c02a 100644 --- a/src/coinbase/tests/balance_test.ts +++ b/src/coinbase/tests/balance_test.ts @@ -9,7 +9,7 @@ describe("Balance", () => { const balanceModel: BalanceModel = { amount: "1000000000000000000", asset: { - asset_id: Coinbase.assetList.Eth, + asset_id: Coinbase.assets.Eth, network_id: Coinbase.networkList.BaseSepolia, }, }; @@ -21,25 +21,25 @@ describe("Balance", () => { }); it("returns a new Balance object with the correct asset_id", () => { - expect(balance.assetId).toBe(Coinbase.assetList.Eth); + expect(balance.assetId).toBe(Coinbase.assets.Eth); }); }); describe(".fromModelAndAssetId", () => { const amount = new Decimal(1); const balanceModel: BalanceModel = { - asset: { asset_id: Coinbase.assetList.Eth, network_id: Coinbase.networkList.BaseSepolia }, + asset: { asset_id: Coinbase.assets.Eth, network_id: Coinbase.networkList.BaseSepolia }, amount: "1000000000000000000", }; - const balance = Balance.fromModelAndAssetId(balanceModel, Coinbase.assetList.Eth); + const balance = Balance.fromModelAndAssetId(balanceModel, Coinbase.assets.Eth); it("returns a new Balance object with the correct amount", () => { expect(balance.amount).toEqual(amount); }); it("returns a new Balance object with the correct asset_id", () => { - expect(balance.assetId).toBe(Coinbase.assetList.Eth); + expect(balance.assetId).toBe(Coinbase.assets.Eth); }); }); }); diff --git a/src/coinbase/tests/user_test.ts b/src/coinbase/tests/user_test.ts index 3a875f28..3db4cf35 100644 --- a/src/coinbase/tests/user_test.ts +++ b/src/coinbase/tests/user_test.ts @@ -442,7 +442,7 @@ describe("User Class", () => { await expect( unhydratedWallet.createTransfer( new Decimal("500000000000000000"), - Coinbase.assetList.Eth, + Coinbase.assets.Eth, address1, ), ).rejects.toThrow(InternalError); @@ -463,7 +463,7 @@ describe("User Class", () => { const mockWalletBalance: BalanceModel = { amount: "5000000000000000000", asset: { - asset_id: Coinbase.assetList.Eth, + asset_id: Coinbase.assets.Eth, network_id: Coinbase.networkList.BaseSepolia, decimals: 18, }, @@ -491,7 +491,7 @@ describe("User Class", () => { expect(wallet.getAddress(addressListModel.data[0].address_id)?.getId()).toBe( addressListModel.data[0].address_id, ); - const balance = await wallet.getBalance(Coinbase.assetList.Eth); + const balance = await wallet.getBalance(Coinbase.assets.Eth); expect(balance).toEqual(new Decimal("5")); const balanceMap = await wallet.getBalances(); diff --git a/src/coinbase/tests/utils.ts b/src/coinbase/tests/utils.ts index 64722039..1bdf60bf 100644 --- a/src/coinbase/tests/utils.ts +++ b/src/coinbase/tests/utils.ts @@ -81,7 +81,7 @@ export const VALID_TRANSFER_MODEL: TransferModel = { wallet_id: walletId, address_id: ethers.Wallet.createRandom().address, destination: "0x4D9E4F3f4D1A8B5F4f7b1F5b5C7b8d6b2B3b1b0b", - asset_id: Coinbase.assetList.Eth, + asset_id: Coinbase.assets.Eth, amount: new Decimal(ethers.parseUnits("100", 18).toString()).toString(), unsigned_payload: "7b2274797065223a22307832222c22636861696e4964223a2230783134613334222c226e6f6e63" + @@ -102,7 +102,7 @@ export const VALID_ADDRESS_BALANCE_LIST: AddressBalanceList = { { amount: "1000000000000000000", asset: { - asset_id: Coinbase.assetList.Eth, + asset_id: Coinbase.assets.Eth, network_id: Coinbase.networkList.BaseSepolia, decimals: 18, }, @@ -132,7 +132,7 @@ export const VALID_ADDRESS_BALANCE_LIST: AddressBalanceList = { export const VALID_BALANCE_MODEL: BalanceModel = { amount: "1000000000000000000", asset: { - asset_id: Coinbase.assetList.Eth, + asset_id: Coinbase.assets.Eth, network_id: Coinbase.networkList.BaseSepolia, }, }; diff --git a/src/coinbase/tests/wallet_test.ts b/src/coinbase/tests/wallet_test.ts index 09af8836..b39290b1 100644 --- a/src/coinbase/tests/wallet_test.ts +++ b/src/coinbase/tests/wallet_test.ts @@ -105,7 +105,7 @@ describe("Wallet Class", () => { const transfer = await wallet.createTransfer( weiAmount, - Coinbase.assetList.Wei, + Coinbase.assets.Wei, destination, intervalSeconds, timeoutSeconds, @@ -122,7 +122,7 @@ describe("Wallet Class", () => { await expect( wallet.createTransfer( weiAmount, - Coinbase.assetList.Wei, + Coinbase.assets.Wei, destination, intervalSeconds, timeoutSeconds, @@ -138,7 +138,7 @@ describe("Wallet Class", () => { await expect( wallet.createTransfer( weiAmount, - Coinbase.assetList.Wei, + Coinbase.assets.Wei, destination, intervalSeconds, timeoutSeconds, @@ -158,7 +158,7 @@ describe("Wallet Class", () => { await expect( wallet.createTransfer( weiAmount, - Coinbase.assetList.Wei, + Coinbase.assets.Wei, destination, intervalSeconds, timeoutSeconds, @@ -171,7 +171,7 @@ describe("Wallet Class", () => { await expect( wallet.createTransfer( insufficientAmount, - Coinbase.assetList.Wei, + Coinbase.assets.Wei, destination, intervalSeconds, timeoutSeconds, @@ -353,7 +353,7 @@ describe("Wallet Class", () => { { amount: "1000000000000000000", asset: { - asset_id: Coinbase.assetList.Eth, + asset_id: Coinbase.assets.Eth, network_id: Coinbase.networkList.BaseSepolia, decimals: 18, }, @@ -388,7 +388,7 @@ describe("Wallet Class", () => { const mockWalletBalance: BalanceModel = { amount: "5000000000000000000", asset: { - asset_id: Coinbase.assetList.Eth, + asset_id: Coinbase.assets.Eth, network_id: Coinbase.networkList.BaseSepolia, decimals: 18, }, @@ -397,43 +397,43 @@ describe("Wallet Class", () => { }); it("should return the correct ETH balance", async () => { - const balanceMap = await wallet.getBalance(Coinbase.assetList.Eth); + const balanceMap = await wallet.getBalance(Coinbase.assets.Eth); expect(balanceMap).toEqual(new Decimal(5)); expect(Coinbase.apiClients.wallet!.getWalletBalance).toHaveBeenCalledTimes(1); expect(Coinbase.apiClients.wallet!.getWalletBalance).toHaveBeenCalledWith( walletId, - Coinbase.assetList.Eth, + Coinbase.assets.Eth, ); }); it("should return the correct GWEI balance", async () => { - const balance = await wallet.getBalance(Coinbase.assetList.Gwei); + const balance = await wallet.getBalance(Coinbase.assets.Gwei); expect(balance).toEqual(GWEI_PER_ETHER.mul(5)); expect(Coinbase.apiClients.wallet!.getWalletBalance).toHaveBeenCalledTimes(1); expect(Coinbase.apiClients.wallet!.getWalletBalance).toHaveBeenCalledWith( walletId, - Coinbase.assetList.Gwei, + Coinbase.assets.Gwei, ); }); it("should return the correct WEI balance", async () => { - const balance = await wallet.getBalance(Coinbase.assetList.Wei); + const balance = await wallet.getBalance(Coinbase.assets.Wei); expect(balance).toEqual(WEI_PER_ETHER.mul(5)); expect(Coinbase.apiClients.wallet!.getWalletBalance).toHaveBeenCalledTimes(1); expect(Coinbase.apiClients.wallet!.getWalletBalance).toHaveBeenCalledWith( walletId, - Coinbase.assetList.Wei, + Coinbase.assets.Wei, ); }); it("should return 0 when the balance is not found", async () => { Coinbase.apiClients.wallet!.getWalletBalance = mockReturnValue({}); - const balance = await wallet.getBalance(Coinbase.assetList.Wei); + const balance = await wallet.getBalance(Coinbase.assets.Wei); expect(balance).toEqual(new Decimal(0)); expect(Coinbase.apiClients.wallet!.getWalletBalance).toHaveBeenCalledTimes(1); expect(Coinbase.apiClients.wallet!.getWalletBalance).toHaveBeenCalledWith( walletId, - Coinbase.assetList.Wei, + Coinbase.assets.Wei, ); }); }); diff --git a/src/coinbase/transfer.ts b/src/coinbase/transfer.ts index 7670742d..f0bbafd2 100644 --- a/src/coinbase/transfer.ts +++ b/src/coinbase/transfer.ts @@ -101,7 +101,7 @@ export class Transfer { public getAmount(): Decimal { const amount = new Decimal(this.model.amount); - if (this.getAssetId() === Coinbase.assetList.Eth) { + if (this.getAssetId() === Coinbase.assets.Eth) { return amount.div(WEI_PER_ETHER); } return amount;