Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 6ac82f9

Browse files
Arrowanajoncinque
andauthored
token-swap typescript: Move things around, fix typing problems (#1643)
* Move things around, fix typing problems * oups output built in src * fix typegen * fix cli * fix linting, apply review comments and add forgotten package-lock.json change * remove typegen.sh and move simpler command to package.json * Move things around, remove babel and rollup * Update packages * Add browser dist to eslintignore Co-authored-by: Arrowana <[email protected]> Co-authored-by: Jon Cinque <[email protected]>
1 parent 25b51bc commit 6ac82f9

30 files changed

+301
-6723
lines changed

ci/js-test-token-swap.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ set -ex
44
cd "$(dirname "$0")/.."
55
source ./ci/solana-version.sh install
66

7-
(cd token/js && npm install)
8-
97
cd token-swap/js
108
npm install
119
npm run lint
12-
npm run flow
13-
npx tsc module.d.ts
10+
npm run build
1411
npm run start-with-test-validator
1512
(cd ../../target/deploy && mv spl_token_swap_production.so spl_token_swap.so)
1613
SWAP_PROGRAM_OWNER_FEE_ADDRESS="HfoTxFR1Tm6kGmWgYWD6J7YHVy1UwqSULUGVLXkJqaKN" npm run start-with-test-validator

token-swap/js/.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/lib
1+
/dist
2+
/dist.browser

token-swap/js/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module.exports = {
1111
'plugin:import/errors',
1212
'plugin:import/warnings',
1313
],
14-
parser: 'babel-eslint',
1514
parserOptions: {
1615
sourceType: 'module',
1716
ecmaVersion: 8,

token-swap/js/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
test-ledger/
2+
dist/
3+
dist.browser/

token-swap/js/babel.config.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

token-swap/js/babel.rollup.config.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

token-swap/js/cli/main.js renamed to token-swap/js/cli/main.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
/**
2-
* Exercises the token-swap program
3-
*
4-
* @flow
5-
*/
6-
71
import {
82
createAccountAndSwapAtomic,
93
createTokenSwap,

token-swap/js/cli/token-swap-test.js renamed to token-swap/js/cli/token-swap-test.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @flow
2-
31
import {
42
Account,
53
Connection,
@@ -9,15 +7,11 @@ import {
97
} from '@solana/web3.js';
108
import {AccountLayout, Token, TOKEN_PROGRAM_ID} from '@solana/spl-token';
119

12-
import {
13-
TokenSwap,
14-
CurveType,
15-
TOKEN_SWAP_PROGRAM_ID,
16-
} from '../client/token-swap';
17-
import {sendAndConfirmTransaction} from '../client/util/send-and-confirm-transaction';
18-
import {newAccountWithLamports} from '../client/util/new-account-with-lamports';
19-
import {url} from '../url';
20-
import {sleep} from '../client/util/sleep';
10+
import {TokenSwap, CurveType, TOKEN_SWAP_PROGRAM_ID} from '../src';
11+
import {sendAndConfirmTransaction} from '../src/util/send-and-confirm-transaction';
12+
import {newAccountWithLamports} from '../src/util/new-account-with-lamports';
13+
import {url} from '../src/util/url';
14+
import {sleep} from '../src/util/sleep';
2115

2216
// The following globals are created by `createTokenSwap` and used by subsequent tests
2317
// Token swap
@@ -76,14 +70,14 @@ const DEFAULT_POOL_TOKEN_AMOUNT = 1000000000;
7670
// Pool token amount to withdraw / deposit
7771
const POOL_TOKEN_AMOUNT = 10000000;
7872

79-
function assert(condition, message) {
73+
function assert(condition: boolean, message?: string) {
8074
if (!condition) {
8175
console.log(Error().stack + ':token-test.js');
8276
throw message || 'Assertion failed';
8377
}
8478
}
8579

86-
let connection;
80+
let connection: Connection;
8781
async function getConnection(): Promise<Connection> {
8882
if (connection) return connection;
8983

@@ -356,7 +350,7 @@ export async function createAccountAndSwapAtomic(): Promise<void> {
356350
let userAccountA = await mintA.createAccount(owner.publicKey);
357351
await mintA.mintTo(userAccountA, owner, [], SWAP_AMOUNT_IN);
358352

359-
// $FlowFixMe[prop-missing]
353+
// @ts-ignore
360354
const balanceNeeded = await Token.getMinBalanceRentForExemptAccount(
361355
connection,
362356
);

token-swap/js/flow-typed/bn.js.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

token-swap/js/flow-typed/bs58.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)