Skip to content

Commit c51b136

Browse files
committed
Updates for trading polygon
1 parent 814e415 commit c51b136

File tree

5 files changed

+175
-41
lines changed

5 files changed

+175
-41
lines changed

src/client/client.ts

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export const BIG_NUMBER_FORMAT = {
277277
prefix: ''
278278
}
279279

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

282282
export const UNLIMITED_APPROVAL = Number.MAX_SAFE_INTEGER
283283

@@ -1123,6 +1123,45 @@ export class Client {
11231123

11241124
this.nashCoreConfig = await initialize(this.initParams)
11251125

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+
11261165
this.publicKey = this.nashCoreConfig.payloadSigningKey.publicKey
11271166
await this.gql.mutate<AddKeysResult, AddKeysArgs>({
11281167
mutation: ADD_KEYS_WITH_WALLETS_MUTATION,
@@ -1131,32 +1170,7 @@ export class Client {
11311170
encryptedSecretKeyNonce: toHex(this.initParams.aead.nonce),
11321171
encryptedSecretKeyTag: toHex(this.initParams.aead.tag),
11331172
signaturePublicKey: this.nashCoreConfig.payloadSigningKey.publicKey,
1134-
wallets: [
1135-
{
1136-
address: this.nashCoreConfig.wallets.neo.address,
1137-
blockchain: 'NEO',
1138-
publicKey: this.nashCoreConfig.wallets.neo.publicKey,
1139-
chainIndex: this.nashCoreConfig.wallets.neo.index
1140-
? this.nashCoreConfig.wallets.neo.index
1141-
: 0
1142-
},
1143-
{
1144-
address: this.nashCoreConfig.wallets.eth.address,
1145-
blockchain: 'ETH',
1146-
publicKey: this.nashCoreConfig.wallets.eth.publicKey,
1147-
chainIndex: this.nashCoreConfig.wallets.eth.index
1148-
? this.nashCoreConfig.wallets.eth.index
1149-
: 0
1150-
},
1151-
{
1152-
address: this.nashCoreConfig.wallets.btc.address,
1153-
blockchain: 'BTC',
1154-
publicKey: this.nashCoreConfig.wallets.btc.publicKey,
1155-
chainIndex: this.nashCoreConfig.wallets.btc.index
1156-
? this.nashCoreConfig.wallets.btc.index
1157-
: 0
1158-
}
1159-
]
1173+
wallets
11601174
}
11611175
})
11621176
}
@@ -2693,20 +2707,24 @@ export class Client {
26932707
}
26942708
const assetData = this.assetData[quantity.currency]
26952709
const blockchain = assetData.blockchain
2710+
26962711
const childKey = this.apiKey.child_keys[
26972712
BLOCKCHAIN_TO_BIP44[blockchain.toUpperCase() as Blockchain]
26982713
]
26992714
const address = childKey.address
2700-
2701-
if (
2702-
blockchain === 'eth' &&
2703-
movementType === MovementTypeDeposit &&
2704-
quantity.currency !== CryptoCurrency.ETH
2705-
) {
2706-
await this.approveAndAwaitAllowance(
2707-
quantity,
2708-
this.opts.ethNetworkSettings.contracts.vault.contract
2709-
)
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+
}
27102728
}
27112729

27122730
const blockchainFees = await this.getBlockchainFees(
@@ -2727,6 +2745,7 @@ export class Client {
27272745

27282746
let preparedMovement: PrepareMovementData['prepareMovement']
27292747
let movementAmount = bnAmount
2748+
27302749
const prepareAMovement = async () => {
27312750
const params = {
27322751
address,
@@ -3190,7 +3209,7 @@ export class Client {
31903209
const assetList = {}
31913210
const assets: Asset[] = await this.listAssets()
31923211
for (const a of assets) {
3193-
if(TRADABLE_CHAINS.includes(a.blockchain.toString().toLowerCase())) {
3212+
if (TRADABLE_CHAINS.includes(a.blockchain.toString().toLowerCase())) {
31943213
assetList[a.symbol] = {
31953214
hash: a.hash,
31963215
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: {

src/constants/currency.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ export enum CryptoCurrency {
180180
YEZ = 'yez',
181181
ZIL = 'zil',
182182
ZPT = 'zpt',
183-
ZRX = 'zrx'
183+
ZRX = 'zrx',
184+
185+
MATIC = 'matic',
186+
DERC20 = 'derc20'
184187
}
185188

186189
export const NEO_SYSTEM_ASSETS = [CryptoCurrency.NEO, CryptoCurrency.GAS]

src/types/common.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ export type InputPayload = Record<string, any>
3232
export enum Blockchain {
3333
NEO = 'neo',
3434
ETH = 'eth',
35-
BTC = 'btc'
35+
BTC = 'btc',
36+
AVAXC = 'avaxc',
37+
POLYGON = 'polygon',
38+
NEO3 = 'neo3'
3639
}
3740

3841
export enum Period {

0 commit comments

Comments
 (0)