@zebec-network/exchange-card-sdk 1.1.10 → 1.1.11

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.
@@ -105,6 +105,10 @@ export declare class NearService {
105
105
  signerId?: string;
106
106
  amount: string;
107
107
  }): Promise<FinalExecutionOutcome>;
108
+ registerAccountInTokenContract(params: {
109
+ signerId?: string;
110
+ tokenContractId: string;
111
+ }): Promise<FinalExecutionOutcome | null>;
108
112
  transferTokens(params: {
109
113
  signerId?: string;
110
114
  amount: string;
@@ -78,11 +78,76 @@ class NearService {
78
78
  });
79
79
  return outcome;
80
80
  }
81
+ async registerAccountInTokenContract(params) {
82
+ const signerId = params.signerId ? params.signerId : this.wallet.signerId;
83
+ const storageBalanceBoundsResult = await this.provider.query({
84
+ request_type: "call_function",
85
+ account_id: params.tokenContractId,
86
+ method_name: "storage_balance_bounds",
87
+ args_base64: Buffer.from(JSON.stringify({})).toString("base64"),
88
+ finality: "optimistic",
89
+ });
90
+ const storageBalanceBounds = JSON.parse(Buffer.from(storageBalanceBoundsResult.result).toString());
91
+ console.debug("storageBalanceBounds:", storageBalanceBounds);
92
+ const storageBalanceResult = await this.provider.query({
93
+ request_type: "call_function",
94
+ account_id: params.tokenContractId,
95
+ method_name: "storage_balance_of",
96
+ args_base64: Buffer.from(JSON.stringify({ account_id: signerId })).toString("base64"),
97
+ finality: "optimistic",
98
+ });
99
+ const storageBalance = JSON.parse(Buffer.from(storageBalanceResult.result).toString());
100
+ console.debug("storageBalance:", storageBalance);
101
+ const GAS = "30000000000000";
102
+ if (!storageBalance ||
103
+ (0, bignumber_js_1.BigNumber)(storageBalance.available).isLessThan(storageBalanceBounds.min)) {
104
+ const action = createFunctionCall("storage_deposit", {
105
+ account_id: signerId,
106
+ registration_only: false,
107
+ }, GAS, storageBalanceBounds.min);
108
+ const outcome = await this.wallet.signAndSendTransaction({
109
+ signerId: signerId,
110
+ receiverId: params.tokenContractId,
111
+ actions: [action],
112
+ });
113
+ return outcome;
114
+ }
115
+ return null;
116
+ }
81
117
  async transferTokens(params) {
82
118
  const signerId = params.signerId ? params.signerId : this.wallet.signerId;
119
+ console.log("signerId:", signerId);
83
120
  const fetchVault = await this.fetchVault("NEAR-USDC");
84
121
  const destination = fetchVault.address;
85
122
  console.debug("destination:", destination);
123
+ let actions = [];
124
+ const GAS = "30000000000000";
125
+ const storageBalanceBoundsResult = await this.provider.query({
126
+ request_type: "call_function",
127
+ account_id: params.tokenContractId,
128
+ method_name: "storage_balance_bounds",
129
+ args_base64: Buffer.from(JSON.stringify({})).toString("base64"),
130
+ finality: "optimistic",
131
+ });
132
+ const storageBalanceBounds = JSON.parse(Buffer.from(storageBalanceBoundsResult.result).toString());
133
+ console.debug("storageBalanceBounds:", storageBalanceBounds);
134
+ const storageBalanceResult = await this.provider.query({
135
+ request_type: "call_function",
136
+ account_id: params.tokenContractId,
137
+ method_name: "storage_balance_of",
138
+ args_base64: Buffer.from(JSON.stringify({ account_id: destination })).toString("base64"),
139
+ finality: "optimistic",
140
+ });
141
+ const storageBalance = JSON.parse(Buffer.from(storageBalanceResult.result).toString());
142
+ console.debug("storageBalance:", storageBalance);
143
+ if (!storageBalance ||
144
+ (0, bignumber_js_1.BigNumber)(storageBalance.available).isLessThan(storageBalanceBounds.min)) {
145
+ const action = createFunctionCall("storage_deposit", {
146
+ account_id: destination,
147
+ registration_only: false,
148
+ }, GAS, storageBalanceBounds.max ? storageBalanceBounds.max : storageBalanceBounds.min);
149
+ actions.push(action);
150
+ }
86
151
  const metadataResult = await this.provider.query({
87
152
  request_type: "call_function",
88
153
  finality: "final",
@@ -95,17 +160,17 @@ class NearService {
95
160
  const parsedAmount = (0, bignumber_js_1.BigNumber)(params.amount)
96
161
  .times((0, bignumber_js_1.BigNumber)(10).pow(tokenDecimals))
97
162
  .toFixed(0);
98
- const GAS = "30000000000000";
99
163
  const secutityDeposit = "1";
100
- const action = createFunctionCall("ft_transfer", {
164
+ const transferAction = createFunctionCall("ft_transfer", {
101
165
  receiver_id: destination,
102
166
  amount: parsedAmount,
103
167
  memo: null,
104
168
  }, GAS, secutityDeposit);
169
+ actions.push(transferAction);
105
170
  const outcome = await this.wallet.signAndSendTransaction({
106
171
  signerId: signerId,
107
172
  receiverId: params.tokenContractId,
108
- actions: [action],
173
+ actions,
109
174
  });
110
175
  return outcome;
111
176
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zebec-network/exchange-card-sdk",
3
- "version": "1.1.10",
3
+ "version": "1.1.11",
4
4
  "description": "An sdk for purchasing silver card in zebec",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",