@audius/sdk 1.0.11 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ /// <reference types="bn.js" />
2
+ /// <reference types="node" />
3
+ import type { Hedgehog } from '@audius/hedgehog';
4
+ import type { EthContracts } from '../ethContracts';
5
+ import type { EthWeb3Manager } from '../ethWeb3Manager';
6
+ import type { IdentityService } from '../identity';
7
+ import type { SolanaWeb3Manager } from '../solana';
8
+ import { BN } from 'ethereumjs-util';
9
+ import { Nullable } from '../../utils';
10
+ export declare type ProxyWormholeConfig = {};
11
+ /** Singleton state-manager for audius proxy wormhole interaction */
12
+ export declare class ProxyWormhole {
13
+ hedgehog: Nullable<Hedgehog>;
14
+ ethWeb3Manager: EthWeb3Manager;
15
+ ethContracts: EthContracts;
16
+ identityService: Nullable<IdentityService>;
17
+ solanaWeb3Manager: SolanaWeb3Manager;
18
+ constructor(hedgehog: Hedgehog | null, ethWeb3Manager: EthWeb3Manager, ethContracts: EthContracts, identityService: IdentityService | null, solanaWeb3Manager: SolanaWeb3Manager);
19
+ /**
20
+ * Locks assets owned by `fromAccount` into the Solana wormhole with a target
21
+ * solanaAccount destination via the provided relayer wallet.
22
+ */
23
+ _getTransferTokensToEthWormholeParams(fromAccount: string, amount: BN, solanaAccount: string): Promise<{
24
+ chainId: number;
25
+ deadline: number;
26
+ recipient: Buffer;
27
+ arbiterFee: BN;
28
+ signedDigest: import("ethereumjs-util").ECDSASignature;
29
+ }>;
30
+ getTransferTokensToEthWormholeMethod(fromAccount: string, amount: BN, solanaAccount: string): Promise<any>;
31
+ }
@@ -17,7 +17,7 @@ export declare type WormholeConfig = {
17
17
  ethBridgeAddress: string;
18
18
  ethTokenBridgeAddress: string;
19
19
  };
20
- /** Singleton state-manager for Audius Eth Contracts */
20
+ /** Singleton state-manager for audius wormhole interaction */
21
21
  export declare class Wormhole {
22
22
  hedgehog: Nullable<Hedgehog>;
23
23
  ethWeb3Manager: EthWeb3Manager;
@@ -1 +1,2 @@
1
1
  export * from './Wormhole';
2
+ export * from './ProxyWormhole';
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@audius/sdk",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "audius": {
5
- "releaseSHA": "5f2f952b49defef75aab2e13ce086178edf8f66c"
5
+ "releaseSHA": "78388a5771c4a3dca52d6805824b8710b17bb280"
6
6
  },
7
7
  "description": "",
8
8
  "main": "dist/index.cjs.js",
@@ -38,6 +38,10 @@ import { ServiceProvider } from './api/ServiceProvider'
38
38
  import type { BaseConstructorArgs } from './api/base'
39
39
  import type { MonitoringCallbacks } from './services/types'
40
40
  import { EntityManager } from './api/entityManager'
41
+ import {
42
+ ProxyWormhole,
43
+ ProxyWormholeConfig
44
+ } from './services/wormhole/ProxyWormhole'
41
45
 
42
46
  type LibsIdentityServiceConfig = {
43
47
  url: string
@@ -71,6 +75,7 @@ type AudiusLibsConfig = {
71
75
  discoveryProviderConfig: LibsDiscoveryProviderConfig
72
76
  creatorNodeConfig: CreatorNodeConfig
73
77
  comstockConfig: LibsComstockConfig
78
+ wormholeConfig: ProxyWormholeConfig
74
79
  captchaConfig: CaptchaConfig
75
80
  hedgehogConfig: LibsHedgehogConfig
76
81
  isServer: boolean
@@ -224,8 +229,7 @@ export class AudiusLibs {
224
229
  }
225
230
 
226
231
  /**
227
- * Configures wormhole
228
- * This is a stubbed version for native
232
+ * Configures proxy-only wormhole
229
233
  */
230
234
  static configWormhole() {
231
235
  return {}
@@ -297,6 +301,7 @@ export class AudiusLibs {
297
301
  creatorNodeConfig: CreatorNodeConfig
298
302
  discoveryProviderConfig: LibsDiscoveryProviderConfig
299
303
  comstockConfig: LibsComstockConfig
304
+ wormholeConfig: ProxyWormholeConfig
300
305
  captchaConfig: CaptchaConfig
301
306
  hedgehogConfig: LibsHedgehogConfig
302
307
  isServer: boolean
@@ -313,6 +318,7 @@ export class AudiusLibs {
313
318
  web3Manager: Nullable<Web3Manager>
314
319
  solanaWeb3Manager: Nullable<SolanaWeb3Manager>
315
320
  contracts: Nullable<AudiusContracts>
321
+ wormholeClient: Nullable<ProxyWormhole>
316
322
  creatorNode: Nullable<CreatorNode>
317
323
  captcha: Nullable<Captcha>
318
324
  schemas?: Schemas
@@ -351,6 +357,7 @@ export class AudiusLibs {
351
357
  discoveryProviderConfig,
352
358
  creatorNodeConfig,
353
359
  comstockConfig,
360
+ wormholeConfig,
354
361
  captchaConfig,
355
362
  hedgehogConfig,
356
363
  isServer,
@@ -371,6 +378,7 @@ export class AudiusLibs {
371
378
  this.creatorNodeConfig = creatorNodeConfig
372
379
  this.discoveryProviderConfig = discoveryProviderConfig
373
380
  this.comstockConfig = comstockConfig
381
+ this.wormholeConfig = wormholeConfig
374
382
  this.captchaConfig = captchaConfig
375
383
  this.hedgehogConfig = hedgehogConfig
376
384
  this.isServer = isServer
@@ -386,12 +394,13 @@ export class AudiusLibs {
386
394
  this.ethContracts = null
387
395
  this.web3Manager = null
388
396
  this.solanaWeb3Manager = null
397
+ this.wormholeClient = null
389
398
  this.contracts = null
390
399
  this.creatorNode = null
391
400
  this.captcha = null
392
401
  this.comstock = null
393
402
 
394
- // // API
403
+ // API
395
404
  this.ServiceProvider = null
396
405
  this.Account = null
397
406
  this.User = null
@@ -506,6 +515,20 @@ export class AudiusLibs {
506
515
  contractsToInit.push(this.contracts.init())
507
516
  }
508
517
  await Promise.all(contractsToInit)
518
+ if (
519
+ this.wormholeConfig &&
520
+ this.ethWeb3Manager &&
521
+ this.ethContracts &&
522
+ this.solanaWeb3Manager
523
+ ) {
524
+ this.wormholeClient = new ProxyWormhole(
525
+ this.hedgehog,
526
+ this.ethWeb3Manager,
527
+ this.ethContracts,
528
+ this.identityService,
529
+ this.solanaWeb3Manager
530
+ )
531
+ }
509
532
 
510
533
  /** Discovery Provider */
511
534
  if (this.discoveryProviderConfig) {
@@ -559,7 +582,7 @@ export class AudiusLibs {
559
582
  this.ethContracts,
560
583
  this.solanaWeb3Manager,
561
584
  null as any,
562
- null as any,
585
+ this.wormholeClient,
563
586
  this.creatorNode,
564
587
  this.comstock,
565
588
  this.captcha,
@@ -0,0 +1,118 @@
1
+ import type { Hedgehog } from '@audius/hedgehog'
2
+ import type { EthContracts } from '../ethContracts'
3
+ import type { EthWeb3Manager } from '../ethWeb3Manager'
4
+ import type { IdentityService } from '../identity'
5
+ import type { SolanaWeb3Manager } from '../solana'
6
+
7
+ import bs58 from 'bs58'
8
+ import { BN, toBuffer } from 'ethereumjs-util'
9
+
10
+ import { Utils, sign, getTransferTokensDigest, Nullable } from '../../utils'
11
+
12
+ export type ProxyWormholeConfig = {}
13
+
14
+ /** Singleton state-manager for audius proxy wormhole interaction */
15
+ export class ProxyWormhole {
16
+ hedgehog: Nullable<Hedgehog>
17
+ ethWeb3Manager: EthWeb3Manager
18
+ ethContracts: EthContracts
19
+ identityService: Nullable<IdentityService>
20
+ solanaWeb3Manager: SolanaWeb3Manager
21
+
22
+ constructor(
23
+ hedgehog: Hedgehog | null,
24
+ ethWeb3Manager: EthWeb3Manager,
25
+ ethContracts: EthContracts,
26
+ identityService: IdentityService | null,
27
+ solanaWeb3Manager: SolanaWeb3Manager
28
+ ) {
29
+ // Wormhole service dependecies
30
+ this.hedgehog = hedgehog
31
+ this.ethWeb3Manager = ethWeb3Manager
32
+ this.ethContracts = ethContracts
33
+ this.identityService = identityService
34
+ this.solanaWeb3Manager = solanaWeb3Manager
35
+ }
36
+
37
+ /**
38
+ * Locks assets owned by `fromAccount` into the Solana wormhole with a target
39
+ * solanaAccount destination via the provided relayer wallet.
40
+ */
41
+ async _getTransferTokensToEthWormholeParams(
42
+ fromAccount: string,
43
+ amount: BN,
44
+ solanaAccount: string
45
+ ) {
46
+ if (!this.hedgehog) {
47
+ throw new Error(
48
+ 'Hedgehog required for _getTransferTokensToEthWormholeParams'
49
+ )
50
+ }
51
+ const web3 = this.ethWeb3Manager.getWeb3()
52
+ const wormholeClientAddress =
53
+ this.ethContracts.WormholeClient.contractAddress
54
+
55
+ const chainId = await web3.eth.getChainId()
56
+
57
+ const currentBlockNumber = await web3.eth.getBlockNumber()
58
+ const currentBlock = await web3.eth.getBlock(currentBlockNumber)
59
+
60
+ // 1 hour, sufficiently far in future
61
+ const deadline = (currentBlock.timestamp as unknown as number) + 60 * 60 * 1
62
+ const solanaB58 = bs58.decode(solanaAccount).toString('hex')
63
+ const recipient = toBuffer(`0x${solanaB58}`)
64
+ const nonce = await this.ethContracts.WormholeClient.nonces(fromAccount)
65
+ const arbiterFee = Utils.toBN('0')
66
+
67
+ const digest = getTransferTokensDigest(
68
+ web3,
69
+ 'AudiusWormholeClient',
70
+ wormholeClientAddress,
71
+ chainId,
72
+ {
73
+ from: fromAccount,
74
+ amount,
75
+ recipientChain: chainId,
76
+ recipient,
77
+ arbiterFee
78
+ },
79
+ nonce,
80
+ deadline
81
+ )
82
+ const privateKey = this.hedgehog.getWallet()?.getPrivateKey()
83
+ const signedDigest = sign(digest, privateKey!)
84
+ return {
85
+ chainId,
86
+ deadline,
87
+ recipient,
88
+ arbiterFee,
89
+ signedDigest
90
+ }
91
+ }
92
+
93
+ async getTransferTokensToEthWormholeMethod(
94
+ fromAccount: string,
95
+ amount: BN,
96
+ solanaAccount: string
97
+ ) {
98
+ const { chainId, deadline, recipient, arbiterFee, signedDigest } =
99
+ await this._getTransferTokensToEthWormholeParams(
100
+ fromAccount,
101
+ amount,
102
+ solanaAccount
103
+ )
104
+ const method =
105
+ await this.ethContracts.WormholeClient.WormholeContract.methods.transferTokens(
106
+ fromAccount,
107
+ amount,
108
+ chainId,
109
+ recipient,
110
+ arbiterFee,
111
+ deadline,
112
+ signedDigest.v,
113
+ signedDigest.r,
114
+ signedDigest.s
115
+ )
116
+ return method
117
+ }
118
+ }
@@ -28,7 +28,7 @@ export type WormholeConfig = {
28
28
  ethTokenBridgeAddress: string
29
29
  }
30
30
 
31
- /** Singleton state-manager for Audius Eth Contracts */
31
+ /** Singleton state-manager for audius wormhole interaction */
32
32
  export class Wormhole {
33
33
  hedgehog: Nullable<Hedgehog>
34
34
  ethWeb3Manager: EthWeb3Manager
@@ -1 +1,2 @@
1
1
  export * from './Wormhole'
2
+ export * from './ProxyWormhole'