@xswap-link/sdk 0.10.8 → 0.10.9

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.
Files changed (69) hide show
  1. package/.eslintrc.json +10 -1
  2. package/CHANGELOG.md +6 -0
  3. package/dist/index.global.js +331 -331
  4. package/dist/index.js +9 -9
  5. package/dist/index.mjs +9 -9
  6. package/package.json +6 -3
  7. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/index.tsx +106 -9
  8. package/src/components/Swap/SwapView/SwapButton/index.tsx +11 -11
  9. package/src/constants/index.ts +19 -2
  10. package/src/context/SwapProvider.tsx +7 -3
  11. package/src/services/api.ts +1 -0
  12. package/src/services/svm/README.md +483 -0
  13. package/src/services/svm/bindings/accounts/AllowedOfframp.ts +73 -0
  14. package/src/services/svm/bindings/accounts/Config.ts +153 -0
  15. package/src/services/svm/bindings/accounts/DestChain.ts +113 -0
  16. package/src/services/svm/bindings/accounts/Nonce.ts +97 -0
  17. package/src/services/svm/bindings/accounts/index.ts +15 -0
  18. package/src/services/svm/bindings/accounts/tokenAdminRegistry.ts +128 -0
  19. package/src/services/svm/bindings/errors/anchor.ts +773 -0
  20. package/src/services/svm/bindings/errors/custom.ts +375 -0
  21. package/src/services/svm/bindings/errors/index.ts +62 -0
  22. package/src/services/svm/bindings/instructions/ccipSend.ts +112 -0
  23. package/src/services/svm/bindings/instructions/getFee.ts +73 -0
  24. package/src/services/svm/bindings/instructions/index.ts +4 -0
  25. package/src/services/svm/bindings/programId.ts +6 -0
  26. package/src/services/svm/bindings/types/BaseChain.ts +92 -0
  27. package/src/services/svm/bindings/types/BaseConfig.ts +184 -0
  28. package/src/services/svm/bindings/types/CodeVersion.ts +88 -0
  29. package/src/services/svm/bindings/types/CrossChainAmount.ts +53 -0
  30. package/src/services/svm/bindings/types/DestChainConfig.ts +76 -0
  31. package/src/services/svm/bindings/types/DestChainState.ts +76 -0
  32. package/src/services/svm/bindings/types/GetFeeResult.ts +72 -0
  33. package/src/services/svm/bindings/types/LockOrBurnInV1.ts +102 -0
  34. package/src/services/svm/bindings/types/LockOrBurnOutV1.ts +79 -0
  35. package/src/services/svm/bindings/types/RampMessageHeader.ts +94 -0
  36. package/src/services/svm/bindings/types/RateLimitConfig.ts +72 -0
  37. package/src/services/svm/bindings/types/RateLimitTokenBucket.ts +76 -0
  38. package/src/services/svm/bindings/types/ReleaseOrMintInV1.ts +156 -0
  39. package/src/services/svm/bindings/types/ReleaseOrMintOutV1.ts +53 -0
  40. package/src/services/svm/bindings/types/RemoteAddress.ts +61 -0
  41. package/src/services/svm/bindings/types/RemoteConfig.ts +86 -0
  42. package/src/services/svm/bindings/types/RestoreOnAction.ts +120 -0
  43. package/src/services/svm/bindings/types/SVM2AnyMessage.ts +128 -0
  44. package/src/services/svm/bindings/types/SVM2AnyRampMessage.ts +166 -0
  45. package/src/services/svm/bindings/types/SVM2AnyTokenTransfer.ts +118 -0
  46. package/src/services/svm/bindings/types/SVMTokenAmount.ts +64 -0
  47. package/src/services/svm/bindings/types/index.ts +78 -0
  48. package/src/services/svm/core/client/accounts.ts +97 -0
  49. package/src/services/svm/core/client/events.ts +95 -0
  50. package/src/services/svm/core/client/fee.ts +279 -0
  51. package/src/services/svm/core/client/index.ts +150 -0
  52. package/src/services/svm/core/client/send.ts +607 -0
  53. package/src/services/svm/core/client/utils.ts +131 -0
  54. package/src/services/svm/core/models.ts +236 -0
  55. package/src/services/svm/index.ts +32 -0
  56. package/src/services/svm/utils/conversion.ts +62 -0
  57. package/src/services/svm/utils/errors.ts +51 -0
  58. package/src/services/svm/utils/keypair.ts +19 -0
  59. package/src/services/svm/utils/logger.ts +171 -0
  60. package/src/services/svm/utils/pdas/common.ts +15 -0
  61. package/src/services/svm/utils/pdas/feeQuoter.ts +68 -0
  62. package/src/services/svm/utils/pdas/index.ts +12 -0
  63. package/src/services/svm/utils/pdas/receiver.ts +58 -0
  64. package/src/services/svm/utils/pdas/rmnRemote.ts +23 -0
  65. package/src/services/svm/utils/pdas/router.ts +328 -0
  66. package/src/services/svm/utils/pdas/tokenpool.ts +161 -0
  67. package/src/services/svm/utils/transaction.ts +132 -0
  68. package/src/utils/validation.ts +7 -3
  69. package/tsconfig.json +2 -1
@@ -0,0 +1,113 @@
1
+ import { PublicKey, Connection } from "@solana/web3.js"
2
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
+ import { PROGRAM_ID } from "../programId"
6
+
7
+ export interface DestChainFields {
8
+ version: number
9
+ chainSelector: BN
10
+ state: types.DestChainStateFields
11
+ config: types.DestChainConfigFields
12
+ }
13
+
14
+ export interface DestChainJSON {
15
+ version: number
16
+ chainSelector: string
17
+ state: types.DestChainStateJSON
18
+ config: types.DestChainConfigJSON
19
+ }
20
+
21
+ export class DestChain {
22
+ readonly version: number
23
+ readonly chainSelector: BN
24
+ readonly state: types.DestChainState
25
+ readonly config: types.DestChainConfig
26
+
27
+ static readonly discriminator = Buffer.from([
28
+ 77, 18, 241, 132, 212, 54, 218, 16,
29
+ ])
30
+
31
+ static readonly layout = borsh.struct([
32
+ borsh.u8("version"),
33
+ borsh.u64("chainSelector"),
34
+ types.DestChainState.layout("state"),
35
+ types.DestChainConfig.layout("config"),
36
+ ])
37
+
38
+ constructor(fields: DestChainFields) {
39
+ this.version = fields.version
40
+ this.chainSelector = fields.chainSelector
41
+ this.state = new types.DestChainState({ ...fields.state })
42
+ this.config = new types.DestChainConfig({ ...fields.config })
43
+ }
44
+
45
+ static async fetch(
46
+ c: Connection,
47
+ address: PublicKey,
48
+ programId: PublicKey = PROGRAM_ID
49
+ ): Promise<DestChain | null> {
50
+ const info = await c.getAccountInfo(address)
51
+
52
+ if (info === null) {
53
+ return null
54
+ }
55
+ if (!info.owner.equals(programId)) {
56
+ throw new Error("account doesn't belong to this program")
57
+ }
58
+
59
+ return this.decode(info.data)
60
+ }
61
+
62
+ static async fetchMultiple(
63
+ c: Connection,
64
+ addresses: PublicKey[],
65
+ programId: PublicKey = PROGRAM_ID
66
+ ): Promise<Array<DestChain | null>> {
67
+ const infos = await c.getMultipleAccountsInfo(addresses)
68
+
69
+ return infos.map((info) => {
70
+ if (info === null) {
71
+ return null
72
+ }
73
+ if (!info.owner.equals(programId)) {
74
+ throw new Error("account doesn't belong to this program")
75
+ }
76
+
77
+ return this.decode(info.data)
78
+ })
79
+ }
80
+
81
+ static decode(data: Buffer): DestChain {
82
+ if (!data.slice(0, 8).equals(DestChain.discriminator)) {
83
+ throw new Error("invalid account discriminator")
84
+ }
85
+
86
+ const dec = DestChain.layout.decode(data.slice(8))
87
+
88
+ return new DestChain({
89
+ version: dec.version,
90
+ chainSelector: dec.chainSelector,
91
+ state: types.DestChainState.fromDecoded(dec.state),
92
+ config: types.DestChainConfig.fromDecoded(dec.config),
93
+ })
94
+ }
95
+
96
+ toJSON(): DestChainJSON {
97
+ return {
98
+ version: this.version,
99
+ chainSelector: this.chainSelector.toString(),
100
+ state: this.state.toJSON(),
101
+ config: this.config.toJSON(),
102
+ }
103
+ }
104
+
105
+ static fromJSON(obj: DestChainJSON): DestChain {
106
+ return new DestChain({
107
+ version: obj.version,
108
+ chainSelector: new BN(obj.chainSelector),
109
+ state: types.DestChainState.fromJSON(obj.state),
110
+ config: types.DestChainConfig.fromJSON(obj.config),
111
+ })
112
+ }
113
+ }
@@ -0,0 +1,97 @@
1
+ import { PublicKey, Connection } from "@solana/web3.js"
2
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
+ import { PROGRAM_ID } from "../programId"
6
+
7
+ export interface NonceFields {
8
+ version: number
9
+ counter: BN
10
+ }
11
+
12
+ export interface NonceJSON {
13
+ version: number
14
+ counter: string
15
+ }
16
+
17
+ export class Nonce {
18
+ readonly version: number
19
+ readonly counter: BN
20
+
21
+ static readonly discriminator = Buffer.from([
22
+ 143, 197, 147, 95, 106, 165, 50, 43,
23
+ ])
24
+
25
+ static readonly layout = borsh.struct([
26
+ borsh.u8("version"),
27
+ borsh.u64("counter"),
28
+ ])
29
+
30
+ constructor(fields: NonceFields) {
31
+ this.version = fields.version
32
+ this.counter = fields.counter
33
+ }
34
+
35
+ static async fetch(
36
+ c: Connection,
37
+ address: PublicKey,
38
+ programId: PublicKey = PROGRAM_ID
39
+ ): Promise<Nonce | null> {
40
+ const info = await c.getAccountInfo(address)
41
+
42
+ if (info === null) {
43
+ return null
44
+ }
45
+ if (!info.owner.equals(programId)) {
46
+ throw new Error("account doesn't belong to this program")
47
+ }
48
+
49
+ return this.decode(info.data)
50
+ }
51
+
52
+ static async fetchMultiple(
53
+ c: Connection,
54
+ addresses: PublicKey[],
55
+ programId: PublicKey = PROGRAM_ID
56
+ ): Promise<Array<Nonce | null>> {
57
+ const infos = await c.getMultipleAccountsInfo(addresses)
58
+
59
+ return infos.map((info) => {
60
+ if (info === null) {
61
+ return null
62
+ }
63
+ if (!info.owner.equals(programId)) {
64
+ throw new Error("account doesn't belong to this program")
65
+ }
66
+
67
+ return this.decode(info.data)
68
+ })
69
+ }
70
+
71
+ static decode(data: Buffer): Nonce {
72
+ if (!data.slice(0, 8).equals(Nonce.discriminator)) {
73
+ throw new Error("invalid account discriminator")
74
+ }
75
+
76
+ const dec = Nonce.layout.decode(data.slice(8))
77
+
78
+ return new Nonce({
79
+ version: dec.version,
80
+ counter: dec.counter,
81
+ })
82
+ }
83
+
84
+ toJSON(): NonceJSON {
85
+ return {
86
+ version: this.version,
87
+ counter: this.counter.toString(),
88
+ }
89
+ }
90
+
91
+ static fromJSON(obj: NonceJSON): Nonce {
92
+ return new Nonce({
93
+ version: obj.version,
94
+ counter: new BN(obj.counter),
95
+ })
96
+ }
97
+ }
@@ -0,0 +1,15 @@
1
+ export { AllowedOfframp } from "./AllowedOfframp";
2
+ export type {
3
+ AllowedOfframpFields,
4
+ AllowedOfframpJSON,
5
+ } from "./AllowedOfframp";
6
+ export { Config } from "./Config";
7
+ export type { ConfigFields, ConfigJSON } from "./Config";
8
+ export { DestChain } from "./DestChain";
9
+ export type { DestChainFields, DestChainJSON } from "./DestChain";
10
+ export { Nonce } from "./Nonce";
11
+ export type { NonceFields, NonceJSON } from "./Nonce";
12
+ export {
13
+ TokenAdminRegistry as tokenAdminRegistry,
14
+ TokenAdminRegistryFields as tokenAdminRegistryFields,
15
+ } from "./tokenAdminRegistry";
@@ -0,0 +1,128 @@
1
+ import { PublicKey, Connection } from "@solana/web3.js"
2
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import { PROGRAM_ID } from "../programId"
5
+
6
+ export interface TokenAdminRegistryFields {
7
+ version: number
8
+ administrator: PublicKey
9
+ pendingAdministrator: PublicKey
10
+ lookupTable: PublicKey
11
+ writableIndexes: Array<BN>
12
+ mint: PublicKey
13
+ }
14
+
15
+ export interface TokenAdminRegistryJSON {
16
+ version: number
17
+ administrator: string
18
+ pendingAdministrator: string
19
+ lookupTable: string
20
+ writableIndexes: Array<string>
21
+ mint: string
22
+ }
23
+
24
+ export class TokenAdminRegistry {
25
+ readonly version: number
26
+ readonly administrator: PublicKey
27
+ readonly pendingAdministrator: PublicKey
28
+ readonly lookupTable: PublicKey
29
+ readonly writableIndexes: Array<BN>
30
+ readonly mint: PublicKey
31
+
32
+ static readonly discriminator = Buffer.from([
33
+ 70, 92, 207, 200, 76, 17, 57, 114,
34
+ ])
35
+
36
+ static readonly layout = borsh.struct([
37
+ borsh.u8("version"),
38
+ borsh.publicKey("administrator"),
39
+ borsh.publicKey("pendingAdministrator"),
40
+ borsh.publicKey("lookupTable"),
41
+ borsh.array(borsh.u128(), 2, "writableIndexes"),
42
+ borsh.publicKey("mint"),
43
+ ])
44
+
45
+ constructor(fields: TokenAdminRegistryFields) {
46
+ this.version = fields.version
47
+ this.administrator = fields.administrator
48
+ this.pendingAdministrator = fields.pendingAdministrator
49
+ this.lookupTable = fields.lookupTable
50
+ this.writableIndexes = fields.writableIndexes
51
+ this.mint = fields.mint
52
+ }
53
+
54
+ static async fetch(
55
+ c: Connection,
56
+ address: PublicKey,
57
+ programId: PublicKey = PROGRAM_ID
58
+ ): Promise<TokenAdminRegistry | null> {
59
+ const info = await c.getAccountInfo(address)
60
+
61
+ if (info === null) {
62
+ return null
63
+ }
64
+ if (!info.owner.equals(programId)) {
65
+ throw new Error("account doesn't belong to this program")
66
+ }
67
+
68
+ return this.decode(info.data)
69
+ }
70
+
71
+ static async fetchMultiple(
72
+ c: Connection,
73
+ addresses: PublicKey[],
74
+ programId: PublicKey = PROGRAM_ID
75
+ ): Promise<Array<TokenAdminRegistry | null>> {
76
+ const infos = await c.getMultipleAccountsInfo(addresses)
77
+
78
+ return infos.map((info) => {
79
+ if (info === null) {
80
+ return null
81
+ }
82
+ if (!info.owner.equals(programId)) {
83
+ throw new Error("account doesn't belong to this program")
84
+ }
85
+
86
+ return this.decode(info.data)
87
+ })
88
+ }
89
+
90
+ static decode(data: Buffer): TokenAdminRegistry {
91
+ if (!data.slice(0, 8).equals(TokenAdminRegistry.discriminator)) {
92
+ throw new Error("invalid account discriminator")
93
+ }
94
+
95
+ const dec = TokenAdminRegistry.layout.decode(data.slice(8))
96
+
97
+ return new TokenAdminRegistry({
98
+ version: dec.version,
99
+ administrator: dec.administrator,
100
+ pendingAdministrator: dec.pendingAdministrator,
101
+ lookupTable: dec.lookupTable,
102
+ writableIndexes: dec.writableIndexes,
103
+ mint: dec.mint,
104
+ })
105
+ }
106
+
107
+ toJSON(): TokenAdminRegistryJSON {
108
+ return {
109
+ version: this.version,
110
+ administrator: this.administrator.toString(),
111
+ pendingAdministrator: this.pendingAdministrator.toString(),
112
+ lookupTable: this.lookupTable.toString(),
113
+ writableIndexes: this.writableIndexes.map((item) => item.toString()),
114
+ mint: this.mint.toString(),
115
+ }
116
+ }
117
+
118
+ static fromJSON(obj: TokenAdminRegistryJSON): TokenAdminRegistry {
119
+ return new TokenAdminRegistry({
120
+ version: obj.version,
121
+ administrator: new PublicKey(obj.administrator),
122
+ pendingAdministrator: new PublicKey(obj.pendingAdministrator),
123
+ lookupTable: new PublicKey(obj.lookupTable),
124
+ writableIndexes: obj.writableIndexes.map((item) => new BN(item)),
125
+ mint: new PublicKey(obj.mint),
126
+ })
127
+ }
128
+ }