Skip to content

Commit 8e5aa0e

Browse files
authored
Merge pull request #114 from nash-io/ts/add-polygon
Ts/add polygon
2 parents b9df807 + 0992ecd commit 8e5aa0e

File tree

8 files changed

+198
-48
lines changed

8 files changed

+198
-48
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
<a name="6.3.28"></a>
6+
## [6.3.28](https://github.com/nash-io/api-client-typescript/compare/v6.3.26...v6.3.28) (2022-12-08)
7+
8+
9+
10+
<a name="6.3.26"></a>
11+
## [6.3.26](https://github.com/nash-io/api-client-typescript/compare/v6.3.24...v6.3.26) (2022-12-05)
12+
13+
14+
15+
<a name="6.3.24"></a>
16+
## [6.3.24](https://github.com/nash-io/api-client-typescript/compare/v6.3.22...v6.3.24) (2022-12-05)
17+
18+
19+
520
<a name="6.3.22"></a>
621
## [6.3.22](https://github.com/nash-io/api-client-typescript/compare/v6.3.20...v6.3.22) (2022-03-11)
722

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@neon-exchange/api-client-typescript",
3-
"version": "6.3.22",
3+
"version": "6.3.28",
44
"description": "Official TypeScript client for interacting with the Nash exchange",
55
"main": "build/main/index.js",
66
"typings": "build/main/index.d.ts",
@@ -61,7 +61,7 @@
6161
"dependencies": {
6262
"@absinthe/socket": "0.2.1",
6363
"@neon-exchange/nash-perf": "1.0.4",
64-
"@neon-exchange/nash-protocol": "4.5.12",
64+
"@neon-exchange/nash-protocol": "4.9.5",
6565
"@types/isomorphic-fetch": "0.0.35",
6666
"@types/node": "13.9.8",
6767
"@types/request": "2.48.1",

src/client/client.ts

Lines changed: 59 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ const BLOCKCHAIN_TO_BIP44 = {
255255
[Blockchain.ETH]: BIP44.ETH,
256256
[Blockchain.BTC]: BIP44.BTC,
257257
[Blockchain.NEO]: BIP44.NEO,
258-
[Blockchain.AVAXC]: BIP44.AVAXC
258+
[Blockchain.AVAXC]: BIP44.AVAXC,
259+
[Blockchain.POLYGON]: BIP44.POLYGON
259260
}
260261

261262
/** @internal */
@@ -276,7 +277,7 @@ export const BIG_NUMBER_FORMAT = {
276277
prefix: ''
277278
}
278279

279-
const TRADABLE_CHAINS = ['btc','eth','neo']
280+
const TRADABLE_CHAINS = ['btc', 'eth', 'neo', 'polygon']
280281

281282
export const UNLIMITED_APPROVAL = Number.MAX_SAFE_INTEGER
282283

@@ -1122,6 +1123,45 @@ export class Client {
11221123

11231124
this.nashCoreConfig = await initialize(this.initParams)
11241125

1126+
const wallets = [
1127+
{
1128+
address: this.nashCoreConfig.wallets.neo.address,
1129+
blockchain: 'NEO',
1130+
publicKey: this.nashCoreConfig.wallets.neo.publicKey,
1131+
chainIndex: 1
1132+
},
1133+
{
1134+
address: this.nashCoreConfig.wallets.eth.address,
1135+
blockchain: 'ETH',
1136+
publicKey: this.nashCoreConfig.wallets.eth.publicKey,
1137+
chainIndex: 1
1138+
},
1139+
{
1140+
address: this.nashCoreConfig.wallets.btc.address,
1141+
blockchain: 'BTC',
1142+
publicKey: this.nashCoreConfig.wallets.btc.publicKey,
1143+
chainIndex: 1
1144+
},
1145+
{
1146+
address: `C-0x${this.nashCoreConfig.wallets.avaxc.address}`,
1147+
blockchain: 'AVAXC',
1148+
publicKey: this.nashCoreConfig.wallets.avaxc.publicKey,
1149+
chainIndex: 1
1150+
},
1151+
{
1152+
address: this.nashCoreConfig.wallets.polygon.address,
1153+
blockchain: 'POLYGON',
1154+
publicKey: this.nashCoreConfig.wallets.polygon.publicKey,
1155+
chainIndex: 1
1156+
},
1157+
{
1158+
address: this.nashCoreConfig.wallets.neo3.address,
1159+
blockchain: 'NEO3',
1160+
publicKey: this.nashCoreConfig.wallets.neo3.publicKey,
1161+
chainIndex: 1
1162+
}
1163+
]
1164+
11251165
this.publicKey = this.nashCoreConfig.payloadSigningKey.publicKey
11261166
await this.gql.mutate<AddKeysResult, AddKeysArgs>({
11271167
mutation: ADD_KEYS_WITH_WALLETS_MUTATION,
@@ -1130,32 +1170,7 @@ export class Client {
11301170
encryptedSecretKeyNonce: toHex(this.initParams.aead.nonce),
11311171
encryptedSecretKeyTag: toHex(this.initParams.aead.tag),
11321172
signaturePublicKey: this.nashCoreConfig.payloadSigningKey.publicKey,
1133-
wallets: [
1134-
{
1135-
address: this.nashCoreConfig.wallets.neo.address,
1136-
blockchain: 'NEO',
1137-
publicKey: this.nashCoreConfig.wallets.neo.publicKey,
1138-
chainIndex: this.nashCoreConfig.wallets.neo.index
1139-
? this.nashCoreConfig.wallets.neo.index
1140-
: 0
1141-
},
1142-
{
1143-
address: this.nashCoreConfig.wallets.eth.address,
1144-
blockchain: 'ETH',
1145-
publicKey: this.nashCoreConfig.wallets.eth.publicKey,
1146-
chainIndex: this.nashCoreConfig.wallets.eth.index
1147-
? this.nashCoreConfig.wallets.eth.index
1148-
: 0
1149-
},
1150-
{
1151-
address: this.nashCoreConfig.wallets.btc.address,
1152-
blockchain: 'BTC',
1153-
publicKey: this.nashCoreConfig.wallets.btc.publicKey,
1154-
chainIndex: this.nashCoreConfig.wallets.btc.index
1155-
? this.nashCoreConfig.wallets.btc.index
1156-
: 0
1157-
}
1158-
]
1173+
wallets
11591174
}
11601175
})
11611176
}
@@ -2692,20 +2707,24 @@ export class Client {
26922707
}
26932708
const assetData = this.assetData[quantity.currency]
26942709
const blockchain = assetData.blockchain
2710+
26952711
const childKey = this.apiKey.child_keys[
26962712
BLOCKCHAIN_TO_BIP44[blockchain.toUpperCase() as Blockchain]
26972713
]
26982714
const address = childKey.address
2699-
2700-
if (
2701-
blockchain === 'eth' &&
2702-
movementType === MovementTypeDeposit &&
2703-
quantity.currency !== CryptoCurrency.ETH
2704-
) {
2705-
await this.approveAndAwaitAllowance(
2706-
quantity,
2707-
this.opts.ethNetworkSettings.contracts.vault.contract
2708-
)
2715+
if (blockchain === 'eth' || blockchain === 'polygon') {
2716+
if (
2717+
movementType === MovementTypeDeposit &&
2718+
quantity.currency !== CryptoCurrency.ETH &&
2719+
quantity.currency !== CryptoCurrency.MATIC
2720+
) {
2721+
await this.approveAndAwaitAllowance(
2722+
quantity,
2723+
blockchain === 'eth'
2724+
? this.opts.ethNetworkSettings.contracts.vault.contract
2725+
: this.opts.polygonNetworkSettings.contracts.vault.contract
2726+
)
2727+
}
27092728
}
27102729

27112730
const blockchainFees = await this.getBlockchainFees(
@@ -2726,6 +2745,7 @@ export class Client {
27262745

27272746
let preparedMovement: PrepareMovementData['prepareMovement']
27282747
let movementAmount = bnAmount
2748+
27292749
const prepareAMovement = async () => {
27302750
const params = {
27312751
address,
@@ -3189,7 +3209,7 @@ export class Client {
31893209
const assetList = {}
31903210
const assets: Asset[] = await this.listAssets()
31913211
for (const a of assets) {
3192-
if(TRADABLE_CHAINS.includes(a.blockchain.toString().toLowerCase())) {
3212+
if (TRADABLE_CHAINS.includes(a.blockchain.toString().toLowerCase())) {
31933213
assetList[a.symbol] = {
31943214
hash: a.hash,
31953215
precision: 8,

src/client/environments.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { NEO_NETWORK, BTC_NETWORK, Networks, ETH_NETWORK } from './networks'
1+
import {
2+
NEO_NETWORK,
3+
BTC_NETWORK,
4+
Networks,
5+
ETH_NETWORK,
6+
POLYGON_NETWORK
7+
} from './networks'
28

39
export interface EnvironmentConfig {
410
host: string
@@ -7,6 +13,7 @@ export interface EnvironmentConfig {
713
neoScan?: string
814
neoNetworkSettings?: typeof NEO_NETWORK[Networks.MainNet]
915
ethNetworkSettings?: typeof ETH_NETWORK[Networks.MainNet]
16+
polygonNetworkSettings?: typeof ETH_NETWORK[Networks.MainNet]
1017
btcNetworkSettings?: typeof BTC_NETWORK[Networks.MainNet]
1118
isLocal: boolean
1219
}
@@ -30,6 +37,7 @@ export const EnvironmentConfiguration = {
3037
host: 'app.nash.io',
3138
neoScan: 'https://neoscan.io/api/main_net',
3239
ethNetworkSettings: ETH_NETWORK[Networks.MainNet],
40+
polygonNetworkSettings: POLYGON_NETWORK[Networks.MainNet],
3341
neoNetworkSettings: NEO_NETWORK[Networks.MainNet],
3442
btcNetworkSettings: BTC_NETWORK[Networks.MainNet],
3543
isLocal: false
@@ -38,6 +46,7 @@ export const EnvironmentConfiguration = {
3846
host: 'app.sandbox.nash.io',
3947
neoScan: 'https://explorer.neo.sandbox.nash.io/api/main_net',
4048
ethNetworkSettings: ETH_NETWORK[Networks.Sandbox],
49+
polygonNetworkSettings: POLYGON_NETWORK[Networks.Sandbox],
4150
neoNetworkSettings: NEO_NETWORK[Networks.Sandbox],
4251
btcNetworkSettings: BTC_NETWORK[Networks.Sandbox],
4352
isLocal: false
@@ -46,6 +55,7 @@ export const EnvironmentConfiguration = {
4655
host: 'app.master.nash.io',
4756
neoScan: 'https://neo-local-explorer.master.nash.io/api/main_net',
4857
ethNetworkSettings: ETH_NETWORK[Networks.Master],
58+
polygonNetworkSettings: POLYGON_NETWORK[Networks.Master],
4959
neoNetworkSettings: NEO_NETWORK[Networks.Master],
5060
btcNetworkSettings: BTC_NETWORK[Networks.Master],
5161
isLocal: false
@@ -54,6 +64,7 @@ export const EnvironmentConfiguration = {
5464
host: 'app.staging.nash.io',
5565
neoScan: 'https://neo-local-explorer.staging.nash.io/api/main_net',
5666
ethNetworkSettings: ETH_NETWORK[Networks.Staging],
67+
polygonNetworkSettings: POLYGON_NETWORK[Networks.Staging],
5768
neoNetworkSettings: NEO_NETWORK[Networks.Staging],
5869
btcNetworkSettings: BTC_NETWORK[Networks.Staging],
5970
isLocal: false
@@ -62,6 +73,7 @@ export const EnvironmentConfiguration = {
6273
host: 'app.dev1.nash.io',
6374
neoScan: 'https://neo-local-explorer.dev1.nash.io/api/main_net',
6475
ethNetworkSettings: ETH_NETWORK[Networks.Dev1],
76+
polygonNetworkSettings: POLYGON_NETWORK[Networks.Dev1],
6577
neoNetworkSettings: NEO_NETWORK[Networks.Dev1],
6678
btcNetworkSettings: BTC_NETWORK[Networks.Dev1],
6779
isLocal: false
@@ -70,6 +82,7 @@ export const EnvironmentConfiguration = {
7082
host: 'app.dev2.nash.io',
7183
neoScan: 'https://neo-local-explorer.dev2.nash.io/api/main_net',
7284
ethNetworkSettings: ETH_NETWORK[Networks.Dev2],
85+
polygonNetworkSettings: POLYGON_NETWORK[Networks.Dev2],
7386
neoNetworkSettings: NEO_NETWORK[Networks.Dev2],
7487
btcNetworkSettings: BTC_NETWORK[Networks.Dev2],
7588
isLocal: false
@@ -78,6 +91,7 @@ export const EnvironmentConfiguration = {
7891
host: 'app.dev3.nash.io',
7992
neoScan: 'https://neo-local-explorer.dev3.nash.io/api/main_net',
8093
ethNetworkSettings: ETH_NETWORK[Networks.Dev3],
94+
polygonNetworkSettings: POLYGON_NETWORK[Networks.Dev3],
8195
neoNetworkSettings: NEO_NETWORK[Networks.Dev3],
8296
btcNetworkSettings: BTC_NETWORK[Networks.Dev3],
8397
isLocal: false
@@ -86,6 +100,7 @@ export const EnvironmentConfiguration = {
86100
host: 'app.dev4.nash.io',
87101
neoScan: 'https://neo-local-explorer.dev4.nash.io/api/main_net',
88102
ethNetworkSettings: ETH_NETWORK[Networks.Dev4],
103+
polygonNetworkSettings: POLYGON_NETWORK[Networks.Dev4],
89104
neoNetworkSettings: NEO_NETWORK[Networks.Dev4],
90105
btcNetworkSettings: BTC_NETWORK[Networks.Dev4],
91106
isLocal: false
@@ -94,6 +109,7 @@ export const EnvironmentConfiguration = {
94109
host: 'localhost:4000',
95110
neoScan: 'http://localhost:7000/api/test_net',
96111
ethNetworkSettings: ETH_NETWORK[Networks.LocalNet],
112+
polygonNetworkSettings: POLYGON_NETWORK[Networks.LocalNet],
97113
neoNetworkSettings: NEO_NETWORK[Networks.LocalNet],
98114
btcNetworkSettings: BTC_NETWORK[Networks.LocalNet],
99115
isLocal: true
@@ -102,6 +118,7 @@ export const EnvironmentConfiguration = {
102118
host: 'host.docker.internal:4000',
103119
neoScan: 'http://host.docker.internal:7000/api/test_net',
104120
ethNetworkSettings: ETH_NETWORK[Networks.LocalNet],
121+
polygonNetworkSettings: POLYGON_NETWORK[Networks.LocalNet],
105122
neoNetworkSettings: NEO_NETWORK[Networks.LocalNet],
106123
btcNetworkSettings: BTC_NETWORK[Networks.LocalNet],
107124
isLocal: true
@@ -110,6 +127,7 @@ export const EnvironmentConfiguration = {
110127
host: 'cas',
111128
neoScan: 'http://chain-local-neo/api/main_net',
112129
ethNetworkSettings: ETH_NETWORK[Networks.LocalNet],
130+
polygonNetworkSettings: POLYGON_NETWORK[Networks.LocalNet],
113131
neoNetworkSettings: NEO_NETWORK[Networks.LocalNet],
114132
btcNetworkSettings: BTC_NETWORK[Networks.LocalNet],
115133
isLocal: true

src/client/networks.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,97 @@ export const ETH_NETWORK: NetworkSettingsRecord = {
107107
}
108108
}
109109

110+
export const POLYGON_NETWORK: NetworkSettingsRecord = {
111+
[Networks.MainNet]: {
112+
contracts: {
113+
vault: {
114+
contract: 'replace_me'
115+
}
116+
},
117+
nodes: ['https://replace_me']
118+
},
119+
[Networks.TestNet]: {
120+
contracts: {},
121+
nodes: ['https://matic-mumbai.chainstacklabs.com']
122+
},
123+
[Networks.NexNet]: {
124+
contracts: {},
125+
nodes: []
126+
},
127+
[Networks.LocalNet]: {
128+
contracts: {
129+
vault: {
130+
contract: '0xd720aDf19BdBB0e8d8a832322F24729757c58896'
131+
}
132+
},
133+
nodes: ['https://matic-mumbai.chainstacklabs.com']
134+
},
135+
[Networks.Staging]: {
136+
contracts: {
137+
vault: {
138+
contract: '0xd720aDf19BdBB0e8d8a832322F24729757c58896'
139+
}
140+
},
141+
nodes: ['https://matic-mumbai.chainstacklabs.com']
142+
},
143+
[Networks.Master]: {
144+
contracts: {
145+
vault: {
146+
contract: '0xd720aDf19BdBB0e8d8a832322F24729757c58896'
147+
}
148+
},
149+
nodes: ['https://matic-mumbai.chainstacklabs.com']
150+
},
151+
[Networks.Sandbox]: {
152+
contracts: {
153+
vault: {
154+
contract: '0xd720aDf19BdBB0e8d8a832322F24729757c58896'
155+
}
156+
},
157+
nodes: ['https://matic-mumbai.chainstacklabs.com']
158+
},
159+
[Networks.Dev1]: {
160+
contracts: {
161+
vault: {
162+
contract: '0xd720aDf19BdBB0e8d8a832322F24729757c58896'
163+
}
164+
},
165+
nodes: ['https://matic-mumbai.chainstacklabs.com']
166+
},
167+
[Networks.Dev2]: {
168+
contracts: {
169+
vault: {
170+
contract: '0xd720aDf19BdBB0e8d8a832322F24729757c58896'
171+
}
172+
},
173+
nodes: ['https://matic-mumbai.chainstacklabs.com']
174+
},
175+
[Networks.Dev3]: {
176+
contracts: {
177+
vault: {
178+
contract: '0xd720aDf19BdBB0e8d8a832322F24729757c58896'
179+
}
180+
},
181+
nodes: ['https://matic-mumbai.chainstacklabs.com']
182+
},
183+
[Networks.Dev4]: {
184+
contracts: {
185+
vault: {
186+
contract: '0xd720aDf19BdBB0e8d8a832322F24729757c58896'
187+
}
188+
},
189+
nodes: ['https://matic-mumbai.chainstacklabs.com']
190+
},
191+
[Networks.QA1]: {
192+
contracts: {
193+
vault: {
194+
contract: '0xd720aDf19BdBB0e8d8a832322F24729757c58896'
195+
}
196+
},
197+
nodes: ['https://matic-mumbai.chainstacklabs.com']
198+
}
199+
}
200+
110201
// Contracts for all environments except mainnet, testnet, and nexnet
111202
const LOCAL_NEO_CONTRACTS: NetworkSettings['contracts'] = {
112203
staking: {

0 commit comments

Comments
 (0)