Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix token interface #172

Merged
merged 7 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stellar-plus",
"version": "0.12.3",
"version": "0.12.4",
"description": "beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
41 changes: 20 additions & 21 deletions src/stellar-plus/asset/soroban-token/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Address } from '@stellar/stellar-sdk'
import { Spec } from '@stellar/stellar-sdk/contract'

import { spec as defaultSpec, methods } from 'stellar-plus/asset/soroban-token/constants'
Expand Down Expand Up @@ -61,7 +60,7 @@ export class SorobanTokenHandler extends ContractEngine implements SorobanTokenI
return (await this.invokeContract({
method: methods.initialize,
methodArgs: {
admin: new Address(args.admin),
admin: args.admin,
decimal: args.decimal,
name: args.name,
symbol: args.symbol,
Expand Down Expand Up @@ -98,8 +97,8 @@ export class SorobanTokenHandler extends ContractEngine implements SorobanTokenI
return (await this.invokeContract({
method: methods.set_admin,
methodArgs: {
id: new Address(args.id),
new_admin: new Address(args.new_admin),
id: args.id,
new_admin: args.new_admin,
},
signers: args.signers,
header: args.header,
Expand Down Expand Up @@ -147,7 +146,7 @@ export class SorobanTokenHandler extends ContractEngine implements SorobanTokenI
return (await this.invokeContract({
method: methods.set_authorized,
methodArgs: {
id: new Address(args.id),
id: args.id,
authorize: args.authorize,
},
signers: args.signers,
Expand Down Expand Up @@ -178,7 +177,7 @@ export class SorobanTokenHandler extends ContractEngine implements SorobanTokenI
return (await this.invokeContract({
method: methods.mint,
methodArgs: {
to: new Address(args.to),
to: args.to,
amount: args.amount,
},
signers: args.signers,
Expand Down Expand Up @@ -209,7 +208,7 @@ export class SorobanTokenHandler extends ContractEngine implements SorobanTokenI
return (await this.invokeContract({
method: methods.clawback,
methodArgs: {
from: new Address(args.from),
from: args.from,
amount: args.amount,
},
signers: args.signers,
Expand Down Expand Up @@ -242,8 +241,8 @@ export class SorobanTokenHandler extends ContractEngine implements SorobanTokenI
return (await this.readFromContract({
method: methods.allowance,
methodArgs: {
from: new Address(args.from),
spender: new Address(args.spender),
from: args.from,
spender: args.spender,
},
header: args.header,
})) as i128
Expand Down Expand Up @@ -271,8 +270,8 @@ export class SorobanTokenHandler extends ContractEngine implements SorobanTokenI
return (await this.invokeContract({
method: methods.approve,
methodArgs: {
from: new Address(args.from),
spender: new Address(args.spender),
from: args.from,
spender: args.spender,
amount: args.amount,
expiration_ledger: args.expiration_ledger,
},
Expand All @@ -297,7 +296,7 @@ export class SorobanTokenHandler extends ContractEngine implements SorobanTokenI
return (await this.readFromContract({
method: methods.balance,
methodArgs: {
id: new Address(args.id),
id: args.id,
},
header: args.header,
})) as i128
Expand All @@ -318,7 +317,7 @@ export class SorobanTokenHandler extends ContractEngine implements SorobanTokenI
return (await this.readFromContract({
method: methods.spendable_balance,
methodArgs: {
id: new Address(args.id),
id: args.id,
},
header: args.header,
})) as i128
Expand All @@ -345,8 +344,8 @@ export class SorobanTokenHandler extends ContractEngine implements SorobanTokenI
return (await this.invokeContract({
method: methods.transfer,
methodArgs: {
from: new Address(args.from),
to: new Address(args.to),
from: args.from,
to: args.to,
amount: args.amount,
},
signers: args.signers,
Expand Down Expand Up @@ -377,9 +376,9 @@ export class SorobanTokenHandler extends ContractEngine implements SorobanTokenI
return (await this.invokeContract({
method: methods.transfer_from,
methodArgs: {
spender: new Address(args.spender),
from: new Address(args.from),
to: new Address(args.to),
spender: args.spender,
from: args.from,
to: args.to,
amount: args.amount,
},
signers: args.signers,
Expand Down Expand Up @@ -408,7 +407,7 @@ export class SorobanTokenHandler extends ContractEngine implements SorobanTokenI
return (await this.invokeContract({
method: methods.burn,
methodArgs: {
from: new Address(args.from),
from: args.from,
amount: args.amount,
},
signers: args.signers,
Expand Down Expand Up @@ -438,8 +437,8 @@ export class SorobanTokenHandler extends ContractEngine implements SorobanTokenI
return (await this.invokeContract({
method: methods.burn_from,
methodArgs: {
spender: new Address(args.spender),
from: new Address(args.from),
spender: args.spender,
from: args.from,
amount: args.amount,
},
signers: args.signers,
Expand Down
27 changes: 13 additions & 14 deletions src/stellar-plus/asset/soroban-token/index.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Address } from '@stellar/stellar-sdk'
import { Spec } from '@stellar/stellar-sdk/contract'

import { SorobanTokenHandler } from 'stellar-plus/asset/soroban-token'
Expand Down Expand Up @@ -129,7 +128,7 @@ describe('SorobanToken', () => {

expect(invokeSpy).toHaveBeenCalledExactlyOnceWith({
method: methods.initialize,
methodArgs: { ...initializeArgs, admin: new Address(initializeArgs.admin) },
methodArgs: { ...initializeArgs, admin: initializeArgs.admin },
...MOCKED_TX_INVOCATION,
})
})
Expand All @@ -146,7 +145,7 @@ describe('SorobanToken', () => {

expect(invokeSpy).toHaveBeenCalledExactlyOnceWith({
method: methods.set_admin,
methodArgs: { id: new Address(currentAdmin), new_admin: new Address(newAdmin) },
methodArgs: { id: currentAdmin, new_admin: newAdmin },
...MOCKED_TX_INVOCATION,
})
})
Expand All @@ -164,7 +163,7 @@ describe('SorobanToken', () => {

expect(invokeSpy).toHaveBeenCalledExactlyOnceWith({
method: methods.set_authorized,
methodArgs: { ...setAuthorizedArgs, id: new Address(accountToAuthorize) },
methodArgs: { ...setAuthorizedArgs, id: accountToAuthorize },
...MOCKED_TX_INVOCATION,
})
})
Expand All @@ -180,7 +179,7 @@ describe('SorobanToken', () => {

expect(invokeSpy).toHaveBeenCalledExactlyOnceWith({
method: methods.mint,
methodArgs: { ...mintArgs, to: new Address(recipient) },
methodArgs: { ...mintArgs, to: recipient },
...MOCKED_TX_INVOCATION,
})
})
Expand All @@ -196,7 +195,7 @@ describe('SorobanToken', () => {

expect(invokeSpy).toHaveBeenCalledExactlyOnceWith({
method: methods.burn,
methodArgs: { ...burnArgs, from: new Address(from) },
methodArgs: { ...burnArgs, from: from },
...MOCKED_TX_INVOCATION,
})
})
Expand All @@ -214,7 +213,7 @@ describe('SorobanToken', () => {

expect(invokeSpy).toHaveBeenCalledExactlyOnceWith({
method: methods.clawback,
methodArgs: { ...clawbackArgs, from: new Address(targetAccount) },
methodArgs: { ...clawbackArgs, from: targetAccount },
...MOCKED_TX_INVOCATION,
})
})
Expand All @@ -233,7 +232,7 @@ describe('SorobanToken', () => {

expect(invokeSpy).toHaveBeenCalledExactlyOnceWith({
method: methods.approve,
methodArgs: { ...approveArgs, from: new Address(from), spender: new Address(spender) },
methodArgs: { ...approveArgs, from: from, spender: spender },
...MOCKED_TX_INVOCATION,
})
})
Expand All @@ -251,7 +250,7 @@ describe('SorobanToken', () => {

expect(invokeSpy).toHaveBeenCalledExactlyOnceWith({
method: methods.transfer,
methodArgs: { ...transferArgs, from: new Address(from), to: new Address(to) },
methodArgs: { ...transferArgs, from: from, to: to },
...MOCKED_TX_INVOCATION,
})
})
Expand All @@ -271,7 +270,7 @@ describe('SorobanToken', () => {

expect(invokeSpy).toHaveBeenCalledExactlyOnceWith({
method: methods.transfer_from,
methodArgs: { ...transferArgs, from: new Address(from), to: new Address(to), spender: new Address(spender) },
methodArgs: { ...transferArgs, from: from, to: to, spender: spender },
...MOCKED_TX_INVOCATION,
})
})
Expand All @@ -291,7 +290,7 @@ describe('SorobanToken', () => {

expect(invokeSpy).toHaveBeenCalledExactlyOnceWith({
method: methods.burn_from,
methodArgs: { ...burnFromArgs, from: new Address(from), spender: new Address(spender) },
methodArgs: { ...burnFromArgs, from: from, spender: spender },
...MOCKED_TX_INVOCATION,
})
})
Expand Down Expand Up @@ -375,7 +374,7 @@ describe('SorobanToken', () => {

expect(readSpy).toHaveBeenCalledExactlyOnceWith({
method: methods.balance,
methodArgs: { id: new Address(balanceArgs.id) },
methodArgs: { id: balanceArgs.id },
header: MOCKED_TX_INVOCATION.header,
})
})
Expand All @@ -391,7 +390,7 @@ describe('SorobanToken', () => {

expect(readSpy).toHaveBeenCalledExactlyOnceWith({
method: methods.spendable_balance,
methodArgs: { id: new Address(spendableBalanceArgs.id) },
methodArgs: { id: spendableBalanceArgs.id },
header: MOCKED_TX_INVOCATION.header,
})
})
Expand All @@ -406,7 +405,7 @@ describe('SorobanToken', () => {

expect(readSpy).toHaveBeenCalledExactlyOnceWith({
method: methods.allowance,
methodArgs: { from: new Address(allowanceArgs.from), spender: new Address(allowanceArgs.spender) },
methodArgs: { from: allowanceArgs.from, spender: allowanceArgs.spender },
header: MOCKED_TX_INVOCATION.header,
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Address } from '@stellar/stellar-sdk'
import { Spec } from '@stellar/stellar-sdk/contract'

import { ContractEngine } from 'stellar-plus/core/contract-engine'
Expand Down Expand Up @@ -60,7 +59,7 @@ export class CertificateOfDepositClient extends ContractEngine implements Certif
*/
public async deposit(args: DepositArgs): Promise<void> {
const amount = args.amount as i128
const address = new Address(args.address)
const address = args.address

await this.invokeContract({
method: this.methods.deposit,
Expand All @@ -83,7 +82,7 @@ export class CertificateOfDepositClient extends ContractEngine implements Certif
*
*/
public async withdraw(args: WithdrawArgs): Promise<void> {
const address = new Address(args.address)
const address = args.address
const accept_premature_withdraw = args.acceptPrematureWithdraw as boolean

await this.invokeContract({
Expand All @@ -103,7 +102,7 @@ export class CertificateOfDepositClient extends ContractEngine implements Certif
* @description - Gets the current estimated yield accrued for the account's position so far.
*/
public async getEstimatedYield(args: GetEstimatedYieldArgs): Promise<number> {
const address = new Address(args.address)
const address = args.address

const result: i128 = (await this.readFromContract({
method: this.methods.getEstimatedYield,
Expand All @@ -123,7 +122,7 @@ export class CertificateOfDepositClient extends ContractEngine implements Certif
* @description - Gets the current open position for the account.
*/
public async getPosition(args: GetPositionArgs): Promise<number> {
const address = new Address(args.address)
const address = args.address

const result: i128 = (await this.readFromContract({
method: this.methods.getPosition,
Expand All @@ -142,7 +141,7 @@ export class CertificateOfDepositClient extends ContractEngine implements Certif
* @description - Gets the current estimated premature withdraw for the account. This is the amount that will be received if the account withdraws prematurely, with the penalty applied.
*/
public async getEstimatedPrematureWithdraw(args: GetEstimatedPrematureWithdrawArgs): Promise<number> {
const address = new Address(args.address)
const address = args.address

const result: i128 = (await this.readFromContract({
method: this.methods.getEstimatedPrematureWithdraw,
Expand All @@ -162,7 +161,7 @@ export class CertificateOfDepositClient extends ContractEngine implements Certif
* @description - Gets the current time left for the account. This is the time left until the account can withdraw without penalty.
*/
public async getTimeLeft(args: GetTimeLeftArgs): Promise<number> {
const address = new Address(args.address)
const address = args.address

const result: u64 = (await this.readFromContract({
method: this.methods.getTimeLeft,
Expand Down Expand Up @@ -196,8 +195,8 @@ export class CertificateOfDepositClient extends ContractEngine implements Certif
*/
public async initialize(args: Initialize): Promise<void> {
const { term, compoundStep, yieldRate, minDeposit, penaltyRate } = args
const admin = new Address(args.admin)
const asset = new Address(args.asset)
const admin = args.admin
const asset = args.asset

await this.invokeContract({
method: this.methods.initialize,
Expand Down
Loading